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.

3 Digit binary to decimal conversion

Status
Not open for further replies.
Hello there,

The simplest routine to understand for converting binary to BCD is as follows. This makes it easy to understand but you may wish to use another algorithm anyway.

Say we start with 987, nearly the max count possible for 3 digits.
First, subtract 100 in a loop. Count the number of times you can subtract 100 before the result goes negative...it's 9 times.
Add 100 back to the result, then subtract 10 in a loop. Count the number of times you can subtract 10 before it goes negative...it's 8 times.
Add 10 back, and you have your units: 7.
So your result can be stored in 3 separate registers: 9,8,7

Now i know this takes more than a simple 8 bit subtraction, that's why you would need 16 bit math to do this. You need to create or find an algorithm that works with two registers at a time so you can store the entire required operand, which would be 1023 for a 10 bit ADC. You only need addition and subtraction though.

There is a simple algorithm around too for converting any number of digits, but i cant remember what it is called now.
 
Hello,
I will test this method AND FOR CLEAR view which glass should used to avoid reflection of light falling on it..?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top