Книга: Introduction to Microprocessors and Microcontrollers

Binary coded decimal (BCD)

Binary coded decimal (BCD)

Binary coded decimal numbers are very simple. Each decimal digit is converted to binary and written as a 4-bit or 8-bit binary number. The number 5 would be written as 01012 or 000001012. So far, this is the same as ‘ordinary’ binary but the change occurs when we have more digits.

Consider the number 2510. In regular binary this would convert to 110012. Alternatively, we could convert each digit separately to 4-bit or 8-bit numbers:

2 = 00102 or 0000 00102

5 = 01012 or 0000 01012

Putting these together, 2510 could be written using the 4-bit numbers as 0010 01012. This uses one byte and is called Packed BCD. Alternatively, we could use the 8-bit formats and express 2510 as 0000 0010 0000 01012 and would now use two bytes. This is called Unpacked BCD.

There are two disadvantages. Firstly, many numbers are of increased length after converting to BCD, particularly so if we use unpacked BCD or the numbers are very large like 25?1075. In addition, arithmetic is much more difficult although, generally, microprocessors do have the ability to handle them.

The advantage becomes apparent when the microprocessor is controlling an external device like digits on displays at a filling station or accepting inputs from a keyboard. The coding is simple and does not involve the conversion of the numbers to binary.

Overall

Arithmetic ? use binary

Inputting and outputting numbers ? use BCD

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


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