Hi Sarim,
A byte is made up of 8-bits which can represent 256 numbers, 0 to 255 or -127 to 127 using two's complement arithmetic.
<pre>
0 = 0000 0000
255 = 1111 1111
127 = 0111 1111 // 0 in first bit represents + sign
-127 = 1000 0000 // 1 in first-bit represents - sign
</pre>
Two find the bit representation of a negative number, subtract the number from the highest value the type can represent.
So, to find the bit representation of -3, 256-3 = 253. The bit representation of 253 is:
<pre>
255 = 1111 1111
- 2 = 0000 0010 // need to get to 253, so subtract 2
---------
253 = 1111 1101 // -3 bit representation
</pre>
To find -6: 256 - 6 = 250
<pre>
255 = 1111 1111
- 5 = 0000 0101 // need to get to 250, so subtract 5
---------
250 = 1111 1010 // -6 bit representation
</pre>
I have some notes posted on working with binary, octal and hexadecimal numbers at
file:///D|/Java/jeg/oper/binhex.html.
Hope that helps.
------------------
Jane
The cure for boredom is curiosity.
There is no cure for curiousity.
-- Dorothy Parker