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
Post a Comment