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

1.23 BCD Numbers

1.23 BCD Numbers

BCD (binary coded decimal) numbers are usually used in display systems such as LCDs and 7-segment displays to show numeric values. In BCD, each digit is a 4-bit number from 0 to 9. As an example, Table 1.4 shows the BCD numbers between 0 and 20.

Table 1.4: BCD numbers between 0 and 20

Decimal BCD Binary
0 0000 0000
1 0001 0001
2 0010 0010
3 0011 0011
4 0100 0100
5 0101 0101
6 0110 0110
7 0111 0111
8 1000 1000
9 1001 1001
10 0001 0000 1010
11 0001 0001 1011
12 0001 0010 1100
13 0001 0011 1101
14 0001 0100 1110
15 0001 0101 1111
16 0001 0110 1 0000
17 0001 0111 1 0001
18 0001 1000 1 0010
19 0001 1001 1 0011
20 0010 0000 1 0100

Example 1.38

Write the decimal number 295 as a BCD number.

Solution 1.38

Write the 4-bit binary equivalent of each digit:

2 = 00102 9 = 10012 5 = 01012

The BCD number is 0010 1001 01012.

Example 1.39

Write the decimal equivalent of BCD number 1001 1001 0110 00012.

Solution 1.39

Writing the decimal equivalent of each group of 4-bit yields the decimal number: 9961

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


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