| Author |
pls explain?
|
vikram choudhary .
Greenhorn
Joined: Apr 25, 2007
Posts: 7
|
|
byte i= (byte)129; System.out.println(i); output: -127 why? can anyone explain?
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
As an int, 129 has the following bit representation 00000000000000000000000010000001 When you cast to a byte, you only have the last 8 bits. So you have the byte 10000001 Because the first bit is a 1, this is a negative number. To find out what number it is the negative of, flip all the bits and add 1 You get 01111111 So the number is -127.
|
 |
Chandra Bhatt
Ranch Hand
Joined: Feb 28, 2007
Posts: 1707
|
|
Good Keith!!! Thanks, cmbhatt
|
cmbhatt
|
 |
 |
|
|
subject: pls explain?
|
|
|