system
March 28, 2009, 12:01am
1
Hi , Is there a library to convert binary to bcd.
I want to display a reading from a ADC port and convert the 0 to 1023 to an array of bcd digits ( 4 ) to display on leds.
I can think of one way, eg use itoa and convert it to a a string then minus a number to can back to 0 to 9 , but is there a simple way than this ?
Thank in advance Peter
system
March 28, 2009, 12:32am
2
Some old processors do this automagically with built-in instructions, so I figured it wasn't really magic. Found this nice page with a useful algorithm:
http://www.engr.udayton.edu/faculty/jloomis/ece314/notes/devices/binary_to_BCD/bin_to_BCD.html
For sixteen bit numbers, you'll need three bytes to hold five BCD digits in nibbles, and your result won't be done until you've shifted sixteen times.