How Binary to Hexadecimal Conversion Works
Converting from binary to hexadecimal is a fundamental operation in computing. Here's a step-by-step explanation:
Step 1: Group Binary Digits
First, we group the binary digits into sets of 4 bits, starting from the right. If the leftmost group doesn't have 4 digits, we pad it with leading zeros.
Step 2: Convert Each Group to Hexadecimal
Each 4-bit group corresponds to a single hexadecimal digit:
| Binary (4 bits) |
Decimal |
Hexadecimal |
| 0000 | 0 | 0 |
| 0001 | 1 | 1 |
| 0010 | 2 | 2 |
| 0011 | 3 | 3 |
| 0100 | 4 | 4 |
| 0101 | 5 | 5 |
| 0110 | 6 | 6 |
| 0111 | 7 | 7 |
| 1000 | 8 | 8 |
| 1001 | 9 | 9 |
| 1010 | 10 | A |
| 1011 | 11 | B |
| 1100 | 12 | C |
| 1101 | 13 | D |
| 1110 | 14 | E |
| 1111 | 15 | F |
Step 3: Combine the Hexadecimal Digits
Finally, join the hexadecimal digits in the same order:
Hexadecimal to Binary Conversion
To convert from hexadecimal to binary, we reverse the process:
- Convert each hexadecimal digit to its 4-bit binary equivalent
- Combine the binary groups in the same order
AB → A B → 1010 1011 → 10101011
Signed Binary Numbers
When dealing with signed binary numbers, we use two's complement representation:
- Positive numbers are represented normally
- Negative numbers: invert all bits and add 1
For example, -5 in 8-bit binary:
- 5 in binary: 00000101
- Invert all bits: 11111010
- Add 1: 11111011
So -5 in 8-bit two's complement is 11111011, which converts to FB in hexadecimal.