Binary and Hex

Hex notation often is used to provide a more convenient view of binary data, such as memory addresses or integers holding bit-flag settings. The reason is that each hexadecimal digit corresponds to a four-bit unit. Table A.2 shows this correspondence.

Table A.2. Hexadecimal digits and binary equivalents.
Hexadecimal digitsBinary equivalentHexadecimal digitsBinary equivalent
0000081000
1000191001
20010A1010
30011B1011
40100C1100
50101D1101
60110E1110
70111F1111

To convert a hex value to binary, just replace each hex digit by the corresponding binary equivalent. For example, the hex number 0xA4 corresponds to binary 1010 0100. Similarly, you easily can convert binary values to hex notation by converting each 4-bit unit into the equivalent ...

Get The Waite Group's C++ Primer Plus, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.