Originally Posted by

**Junky** I'll explain it in terms of binary numbers.

The int 130 is 0000 0000 0000 0000 0000 0000 1000 0010 (32 bits).

No wif we try and stuff that number into a byte which only has 8 bits then only the right hand 8 bits are kept.

Therefore the byte will have the value 1000 0010.

The far left bit indicates the sign (1 is negative and 0 is positive), therefore the number in the byte is negative but what negative number is it?

Java uses 2s compliment for its numbers. To convert the number we invert all the bits (change 1 to 0 and 0 to 1) and then add 1.

Byte: 1000 0010

Inverted: 0111 1101

Add one: 0111 1110

The final binary number is 126. Therefore the value in the byte is -126.

As to what Herb is on about is you can calculate what the final value is by doing some modulo magic on the int value. I'm not a math magician so I'm not sure what the exact formula is.