Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

C program to convert 4 BCD digts to 16 binary .

Status
Not open for further replies.

xbop

New Member
I use MIcrochip Pic16F946 for my project. The project has 4 digits for setting up Private ID code so that multiple users can use this controller without interference. I want to write c code to convert this 4 BCD digits to 16 Binary number. Remenber, 1 BCD digit represent 4 bits in binary or 0 to 9 in decimal.

Can anyone, help me write this code, assumeing it is pa:confused:cked BCD.
 
Like this ?

unsigned int bcdNum = 0x1234;
unsigned int value;

value = (bcdNum & 0x000F)*1; // units
bcdNum = bcdNum>>4;
value += (bcdNum & 0x000F)*10; // tens
bcdNum = bcdNum>>4;
...

EDIT: Forgot to shift :)
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top