Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Forums > General Electronics Chat


General Electronics Chat This forum is for general chat about electronics, eg: Dont know what a part does? Dont know how to read a circuit? Want to get an opinion?

Reply
 
Thread Tools Display Modes
Old 9th March 2004, 01:53 PM   (permalink)
Default 8 bit binary to BCD conversion

What mathematical formula should i use to convert an 8 bit binary to BCD?

for example in 4 bit binary, i just add 0110 to the binary if it is >1001 to produce the BCD. i realise this formula doesn't work when the decimal equivalent of the binary is 20 or more.
Spectacular Butter is offline   Reply With Quote
Old 11th March 2004, 08:50 AM   (permalink)
Default

Try this algorithm

Let N = the binary number to be converted, for an 8 bit number, N < 256.

I'll use decimal numbers rather than binary for simplicity.

Let H = the hundreds digit, T = the tens digit, U = the units digit.

Initialise H = 0, T = 0

A If N < 100 then GOTO B

N = N - 100, H = H + 1, GOTO A
(at the end of this loop, H = the hundreds digit)

B If N < 10 then GOTO C

N = N - 10, T = T + 1, GOTO B
(at the end of this loop, T = the tens digit)

C U = N
(ie. the remainder is the units digit)

So the BCD number is H T U

Len
ljcox is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 05:50 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.