Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

bcd to decimal conversion

Status
Not open for further replies.

raman00084

Full Member level 6
Full Member level 6
Joined
Nov 29, 2010
Messages
375
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Visit site
Activity points
4,076
please send sample program for bcd to decimal conversion in c

i am using pic16f877a ccs complier
 

In two digit BCD say 23 is written as 0010 0011. So, to convert it to decimal you have to do something like this


Code C - [expand]
1
decNum = ((bcdNum >> 4) * 10) + (bcdNum & 0b00001111)



23 is a byte (upto 255 is a byte)

BCD 23 will be stored as 00100011

00100011 >> 4 = 00000010 = 2 decimal

2 * 10 = 20 decimal

00100011 & 0b00001111 = 00000011 = 3

20 + 3 = 23 decimal
 

for variable unsigned char data
perform

((((data & 0xF0 )>>4) * 10) + (data&0xF));
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top