posted 16 years ago
1 byte = 8 bits
The relationship between the number of bits and how many binary values can be had using them is
87654321
2^82^72^62^52^42^32^22^1
What this means is, using 1 bit you can have 2^1 = 2 values. In other words, if there was only one bit to represent your data, you can only have one of the two values: Either a one, or a zero. If you had two bits, you would have 2^2 = 4 possible combinations to represent the data, and those would be: 00, 01, 10, 11 (0,1,2 and 3 in decimal). Likewise, using 8 bits you would have 2 ^ 8 possible combinations 00000000 through 11111111 (0 through 255 decimal). Now, if you were to represent negative numbers also using the same number of bits how would you do it? It's easy. Use the MSB (most significant bit, or the left most bit) as a sign bit. If we did that, we are left with 2^7 (128) possible combinations, and that includes a zero. So, now, based on the value of MSB, you identify whether it is a positive number or a negative one
MSB Lower bitsDecimal
0 0000000 0
01111111127
10000000-128
11111111-1
In general, we can say that with "n" number of bits, the integer values range from [-2^(n-1)] to [(2^(n-1)) - 1]
[ June 28, 2004: Message edited by: Anil Hulikal ]