Casting long to byte in Java -


i unable understand following:

in java,

long l = 130l;   byte b = (byte)l; 

if print value of b, why -126? bit representation of long l?

bytes signed in java - range of values -128 127 inclusive.

the bit pattern 130 long, when truncated 8 bits, bit pattern -126 byte.

as example:

int x = 255; byte b = (byte) x; // b -1 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -