Chad McAte wrote:
why does this result in 44
int a = 300;
byte b = 0;
b =(byte) a;
The bit pattern for a 300 value int is ... 0000 0000 0000 0000 0000 0001 0010 1100. When you explicitly cast it to a byte, even though this value doesn't fall into the range of the byte, the compiler will use the same bit pattern (for the lower 8 bits only). And under twos complement rules, the bit pattern of 0010 1100, as a byte is 44.
Henry