Java Reference
In-Depth Information
1011111 1011 0011
101
1111
1011
0011
101111110110011 2 = 5FB3 16
5
F
B
3
5F B 3
FIGURE B.7 Shortcut conversion from binary to hexadecimal
40 C 6
0100
0000
0110
1100
40C6 16 = 100000011000110 2
1000000 1100 0110
FIGURE B.8 Shortcut conversion from hexadecimal to binary
To go from hexadecimal to binary, we reverse this process, expanding each
hexadecimal digit into four binary digits. Note that you may have to add lead-
ing zeros to the binary version of each expanded hexadecimal digit if necessary
to make four binary digits. Figure B.8 shows the conversion of the hexadecimal
value 40C6 to binary.
Why do we section the bits into groups of four when converting from binary
to hexadecimal? The shortcut conversions work between binary and any base that
is a power of 2. We section the bits into groups of that power. Since 2 4 = 16, we
section the bits in groups of four.
Converting from binary to octal is the same process except that the bits are
sectioned into groups of three, since 2 3 = 8. Likewise, when converting from octal
to binary, we expand each octal digit into three bits.
To convert between, say, hexadecimal and octal is now a process of doing two
shortcut conversions. First convert from hexadecimal to binary, then take that
result and perform a shortcut conversion from binary to octal.
By the way, these types of shortcut conversions can be performed between any
base B and any base that is a power of B . For example, conversions between base
3 and base 9 can be accomplished using the shortcut grouping technique, section-
ing or expanding digits into groups of two, since 3 2 = 9.
 
Search WWH ::




Custom Search