Странное поведение, когда Java преобразует int в байт? - PullRequest
126 голосов
/ 09 мая 2009
int i =132;

byte b =(byte)i; System.out.println(b);

Mindboggling. Почему вывод -124?

Ответы [ 11 ]

0 голосов
/ 16 января 2017
 N is input number
case 1: 0<=N<=127  answer=N;
case 2: 128<=N<=256 answer=N-256 
case 3: N>256   
        temp1=N/256;
        temp2=N-temp*256;
        if temp2<=127   then answer=temp2;
        else if temp2>=128  then answer=temp2-256;
case 4: negative  number input
        do same procedure.just change the sign of the solution           
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...