Книга: Advanced PIC Microcontroller Projects in C

1.8 Converting Binary Numbers into Hexadecimal

1.8 Converting Binary Numbers into Hexadecimal

To convert a binary number into hexadecimal, arrange the number in groups of four and find the hexadecimal equivalent of each group. If the number cannot be divided exactly into groups of four, insert zeros to the left of the number as needed so the number of digits are divisible by four.

Example 1.6

Convert binary number 100111112 into hexadecimal.

Solution 1.6

First, divide the number into groups of four, then find the hexadecimal equivalent of each group:

10011111 = 1001 1111
             9    F

The hexadecimal number is 9F16.

Example 1.7

Convert binary number 11101111000011102 into hexadecimal.

Solution 1.7

First, divide the number into groups of four, then find the hexadecimal equivalent of each group:

1110111100001110 = 1110 1111 0000 1110
                     E    F    0    E

The hexadecimal number is EF0E16.

Example 1.8

Convert binary number 1111102 into hexadecimal.

Solution 1.8

Since the number cannot be divided exactly into groups of four, we have to insert, in this case, two zeros to the left of the number so the number of digits is divisible by four:

111110 = 0011 1110
           3    E

The hexadecimal number is 3E16.

Table 1.2 shows the hexadecimal equivalent of numbers 0 to 31.

Table 1.2: Hexadecimal equivalent of decimal numbers

Decimal Hexadecimal Decimal Hexadecimal
0 0 16 10
1 1 17 11
2 2 18 12
3 3 19 13
4 4 20 14
5 5 21 15
6 6 22 16
7 7 23 17
8 8 24 18
9 9 25 19
10 A 26 1A
11 B 27 1B
12 C 28 1C
13 D 29 1D
14 E 30 1E
15 F 31 1F

Оглавление книги


Генерация: 0.620. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз