BCD to decimal conversion in C program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • learnc009
    New Member
    • Jul 2010
    • 1

    #1

    BCD to decimal conversion in C program

    I am working on a project using microchip PIC16F946, for RF controller. The current code have a working private ID code in binary. The LCD has 4 digits And 4 binary digits can only handle a miax of 16 IC code (1111). Now I want to increade the code to random number or as many ID number as need. So I want to use these 4 bidits as 4 BCD. And convert these 4 BCD digits into 16 pure binary or into decimal number. As you know 1 BCD represents 0 to 9 in decimal oe 1 BCD represnts 8 binary bits.

    Anyone, please help me to write a working code to convert 4 BCD digits to 16 Binary or decimal.

    Private email is provides here: Feel free to answer to this email:
    <removed>

    Hope some expertise, samart people out there will reach out and help.

    Thanks.

    learnc
    Last edited by Banfa; Jul 26 '10, 09:14 PM. Reason: email address removed for users security
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    There is no need to convert BCD to decimal, because BCD is already decimal, where each digit is from 0 to 9, encoded by 4 binary digits. Converting to binary will be something like this
    Code:
    for(i=0;i<4;i++)
    {
    result *= 10;
    result += bcd[i];
    }

    Comment

    Working...