View Full Version : Converting decimal to BCD

05-26-2006, 11:39 AM
I have a circuit set up with a BS2 driving a 74HC595. The 595 is connected to two 74LS47 BCD to decimal converters each driving a seven segment LED.
I want to take a decimal number (counter) which can range from 0-99 and put it on the LEDs.
How would be the best way to get my 8 bits properly arranged into 2 BCD friendly nibbles to shift out to the 595?

Chris Savage
05-26-2006, 01:50 PM
Here are two routines I use for converting BCD to Decimal and Decimal to BCD.

counter = (counter.NIB1 * 10) + counter.NIB0
' Convert BCD To Decimal
counter = (counter / 10 << 4) + (counter // 10)

Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)