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.


11 thoughts on “Binary Coded Decimal (BCD) Number System

  1. Following study a couple of of the blog articles for your web site now, and that i truly like your method of blogging. I bookmarked it to my bookmark website list and are checking back soon. Pls consider my internet website too and inform me what you consider. 1353

  2. Aw, this became an extremely good post. In thought I would like to set up writing like that in addition – taking time and actual effort to create a fantastic article but what / points I say I procrastinate alot by means of no indicates appear to get something completed. 386019

  3. Hey, you used to write amazing, but the last couple of posts have been kinda boringK I miss your wonderful writings. Past couple of posts are just a bit out of track! come on! 985054

  4. want to affiliate physical products, then you’d want to probably
    work with Amazon or. Using specific keywords heightens your search engine ranking for applicable searches.
    Learn how to market your home based sewing business online and in your local

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s