bhatti,
In order to understand cast integer value to byte value, which is biger than the range between -128 to 127,
you should understand binary representation for the bit
pattern of byte.
Okay, byte has the binary range of -2^7 to (2^7)-1,
Your code above has integer value 755, i don't know what the binary value of 755(you could calculater or you could keep divide 775 by 2.
when you cast 755 to byte value, you are losing the most significant bits from the left to the right 32 bit in integer representation to 8 bit representation in byte.
for example, if you have 32 bit representation of
0000 0000 0000 1100 1000 1110 1001 0000
when you cast to integer to short value(16bit). what you guess?
1000 1110 1001 0000
above 32 bit representation is plus some big number, but you can have negative number in short!
and what if you cast to byte,
1001 0000
you get UNUSAL negative numbers in byte.
Am i right?
In byte first bit is sign bit, 1 is minus 0 is plus,
hope that it help.
the above example, to me, it look like the code
test the UNSUAL CASE when you cast integer to byte without thinking about the binary bit representation.
[ February 21, 2003: Message edited by: stephen Kang ]