Java Reference
In-Depth Information
which amounts to 13 in the decimal system. In the following figure you can see the decimal equivalents
of 8-bit binary numbers illustrated.
Binary
Decimal
Binary
Decimal
0000 0000
0
1000 0000
128
0000 0001
1
1000 0001
129
0000 0010
2
1000 0010
130
...
...
...
...
0001 0000
16
1001 0000
144
0001 0001
17
1001 0001
145
...
...
...
...
0111 1100
124
1111 1100
252
0111 1101
125
1111 1101
253
0111 1110
126
1111 1110
254
0111 1111
127
1111 1111
255
Note that using just 7 bits we can represent all the decimal numbers from 0 to 127, which is a total of 2 7 ,
or128 numbers, and using all 8 bits we get 256, or 2 8 numbers. In general, if we have n bits we can
represent 2 n positive integers with values from 0 to 2 n -1.
Hexadecimal Numbers
When we get to larger binary numbers, for example:
1111 0101 1011 1001 1110 0001
the notation starts to be a little cumbersome, particularly when you consider that if you apply the same
method to work out what this in decimal, it's only 16,103,905, a miserable 8 decimal digits. You can sit
more angels on a pinhead than that. Well, as it happens, we have an excellent alternative.
Arithmetic to base 16 is a very convenient option. Each digit can have values from 0 to 15 (the digits
from 10 to 15 being represented by the letters A to F as shown in the next figure) and values from 0 to
15 correspond quite nicely with the range of values that four binary digits can represent.
Search WWH ::




Custom Search