Binary Coded Decimal (BCD) Number System

BCD stands for Binary Coded Decimal.

Use Of BCD:

BCD means digits starting from 0 to 9.
In our day to day life we are not using hex values, so sometimes it is quite difficult to work with hex. Hence to reduce the complexity and for the ease of users, 8051 is provided with BCD.

Now while working with Embedded Systems, we encounters two terms in BCD number system:

  1. Unpacked BCD:
    Those numbers (in hex) whose upper nibble is zero, are considered as unpacked BCD numbers.
    This means  that in any number if the upper 4 bits are zero, then it is said to be in unpacked format.
    In unpacked BCD format, a single byte has only one BCD number in it.
    Ex:      “0000 1001” and “0000 0110” are unpacked BCD for  9 and 6 respectively.
  2. Packed BCD:
    Those numbers whose upper nibble is not equal to zero, but posses some value is termed as Packed BCD.
    In packed BCD, a single byte has two BCD numbers in it, one in the lower 4 bits and one in upper 4 bits.
    Ex:      “0011 1001” and “0001 0001” are packed BCD for 39 and 11 respectively.
Ok, now we understand what is a BCD number system.
  • Now the Q. is how to convert a hex number into decimal number..??
We can do this by two methods:
  1. In order to convert a hex value in BCD value, we have to add 6 under the number which is higher than 9.

    Consider the following examples.

    • Convert 2Ah in BCD  :

    ~ So, 30h is the BCD value of 2Ah .

    • Convert A2h in BCD  :

      + 60h
      = 102h
      ~So, 102h is the BCD value of A2h.

    • Convert BCh in BCD  :

      + 66h
      = 122h
      ~So, 122h is the BCD value of BCh.

  2. Another method is, by the use of DA Instruction:

    The DA (Decimal Adjust for Addition) instruction is provided in the 8051 to perform the above procedure itself.
    By the use of DA instruction, the controller will automatically add 6 under the value greater than 9 and will show us the BCD value.
    As simple as that.. 🙂

    Use of DA Instruction:
    MOV B,#25h        ; Move 21 hex in Register B
    MOV A,#49h       ; Move 8A hex in Accumulator
    ADD A,B                ; Add Register B with A
    DA A                       ; Convert hex value into BCD value

    After the execution of program we will get 74h in accumulator.

    The DA Instruction works only with Accumulator, you can not use it with any other 8bit or 16bit register.
    The DA instruction is only used after ADD instruction; it will not work after INC operation.

With this, I complete my tutorial on BCD Number System.
Post your doubts in comments.



Chapter Links to Understand Assembly language

Chapter – 1 : The Concepts
Chapter – 2 : Inside the ARM
Chapter – 3 : The Instruction Set
Chapter – 4 : Basic Assembler
Chapter – 6 : Data Structures
Chapter – 7 : Non User Modes

Appendix – 3 : Instruction Set

Pdf Links
00toc.pdf               31-Oct-2005 10:31    21k  
[   ] 01ch.pdf 31-Oct-2005 10:31 139k
[   ] 02ach.pdf 31-Oct-2005 10:31 152k
[   ] 02ch.pdf 31-Oct-2005 10:31 123k
[   ] 03ch.pdf 31-Oct-2005 10:31 180k
[   ] 04ch.pdf 31-Oct-2005 10:31 144k
[   ] 05ach.pdf 31-Oct-2005 10:31 291k
[   ] 05ch.pdf 31-Oct-2005 10:31 156k
[   ] 06ach.pdf 31-Oct-2005 10:31 382k
[   ] 06ch.pdf 31-Oct-2005 10:32 184k
[   ] 07ach.pdf 31-Oct-2005 10:32 216k
[   ] 07ch.pdf 31-Oct-2005 10:32 118k
[   ] 08app1.pdf 31-Oct-2005 10:32 112k
[   ] 09app2.pdf 31-Oct-2005 10:32 123k
[   ] 10app3.pdf 31-Oct-2005 10:33 29k
[   ] 11index.pdf 31-Oct-2005 10:33 61k
[TXT] ReadMe.txt 31-Oct-2005 10:34 1k