Continue to Site

[SOLVED]Help with BCD to Binary

Status
Not open for further replies.

kgavionics

Full Member level 3
Hello guys
I have built a break-out board based on the keyboard encoder 74c923 hooked up to an Arduino UNO (AVR-GCC using Atmel studio 7), which sends a BCD digit each time I press on a key! All is working fine, but I can't figure out how to store the 3 digits into an 8 bit variable!
In the picture attached, the number 123 is stored in 3 memory locations (each digit is stored in a memory location) and I want to store the entered number in a single memory location (binary).
I can easily convert binary to BCD, but I'm struggling to do it the other way around!
Can someone give me a heads-up how to convert from BCD to Binary please?

KlausST

Super Moderator
Staff member
Hi,

I really have no clue how you come to these three numbers.

The only thing I can tell:
123 could be 0b01111011 or 0x7B

****
you surely know that BCD are 4 bits.
with binary value from 0b0000 to 0b1001 and HEX 0x0 to 0x9 and decimal 0 to 9

Klaus

betwixt

Super Moderator
Staff member
Assuming your memory locations are 8 bits wide, the highest number you can store is binary 11111111 or 255 in decimal so you can't store bigger numbers without spanning more locations.

Brian.

kgavionics

Full Member level 3
Assuming your memory locations are 8 bits wide, the highest number you can store is binary 11111111 or 255 in decimal so you can't store bigger numbers without spanning more locations.

Brian.
I'm totally aware that I can't store more than 255! My question is how to convert BCD to binary!
--- Updated ---

Hi,

I really have no clue how you come to these three numbers.

The only thing I can tell:
123 could be 0b01111011 or 0x7B

****
you surely know that BCD are 4 bits.
with binary value from 0b0000 to 0b1001 and HEX 0x0 to 0x9 and decimal 0 to 9

Klaus
I just give an example! I meant any number from 000 to 255 in decimal! I want to implement the 8bit version algorithm, then I can extend it to 16 bits!
Furthermore, I'm aware that BCD numbers are coded in 4 bits! But in my case I store them in one memory location (I set high nibbles to 0).
Now the big question, how to convert BCD number to a binary one!

Last edited:

KlausST

Super Moderator
Staff member
Hi,

the "B" in BCD already means "binary".

Please explain more exactly what you need.

Klaus

crutschow

how to convert BCD number to a binary one!
Multiply the 3rd BCD number by 100, the 2nD BCD number by 10, and then add the three together to get one binary number.

kgavionics

Points: 2

johnny78

Points: 2

kgavionics

Full Member level 3
Multiply the 3rd BCD number by 100, the 2nD BCD number by 10, and then add the three together to get one binary number.
You are the man crutschow! Your suggestion worked like a charm!
Thank you very much!!

KlausST

Super Moderator
Staff member
Hi,

wow,

this has nothing to do with
* encoder 74c923
* BCD
* binary
* memory location

... a lot of confusing information.

btw: what happens if the first of the three digits is 3 or higher?

Klaus

Status
Not open for further replies.