Quote:
Originally Posted by PortalDark
im not really very good at this stuff, could you explain me more a bit?
|
Well, a byte is 8 bits.
A byte (and any other integral type) can be signed or unsigned.
Signed means that the value can be either positve or negative, unsigned means that it can only be positive.
Because a byte is always 8 bits, you need something to indicate whether it's positive or negative.
This is done with the most significant bit. (the most left bit)
Unsigned bytes work like this:
Bit (value): 8 (128); 7 (64); 6 (32); 5 (16); 4 (8); 3 (4); 2 (2); 1 (1)
If a bit is set (it's 1), the value is added to the total.
Example: 6 in binary is 0000 0110. (the third and second least significant bits are set)
Signed bytes are exactly the opposite:
Bit (value): 8 (positive or negative); 7 (64); 6 (32); ...
If the most significant bit isn't set (it's 0), the value is positive.
Example: 0111 1111 is 127. (1 + 2 + 4 + ... + 64)
However, if the most significant bit
is set (it's 1), the value is negative.
It then works in the opposite way, every bit that is set, is
substracted from the total (starts with -1).
Example: 1010 1010 is -86. (-1 - 64 - 16 - 4 - 1)