Discussion in "8051 Discussion Forum" started by    sharath411    Jun 18, 2011.
Sat Jun 18 2011, 09:45 am
#1
Hi friends

how to convert a 24 bit bcd to binary for 8051 in assembly. Ex: 100000 to 186AD



Please help me

Thank You,
Sharath
Sat Jun 18 2011, 10:12 am
#2
Sat Jun 18 2011, 10:33 am
#3

The link you provided is for binary to bcd, but i want bcd to binary



If you know please tell me how to do that

Thanks





[ Edited Sat Jun 18 2011, 10:52 am ]
Tue Jun 21 2011, 01:09 am
#4
its really simple...
lets say you have 0x29 as BCD so to convert it to binary.. just do this..

//this is a pseudo code... kind of..
binary = (x & 0x0F) + (((x>
>
4) &0x0F) * 10);
//here x is BCD number...
Wed Jun 22 2011, 02:58 pm
#5
Thanks Ajay,

But i want to convert 6 digit decimal to binary, what you provided is only for 2 digit..

Please help me....
Thu Jun 23 2011, 04:50 am
#6
Help you by doing it for you, or help you figure out how to do it? There is a difference...

Ajay has demonstrated the technique. Binary Coded Decimal numbers are coded such that each nibble (which means 4 bits) has a value in it that represents the ones, tens, hundreds, thousands, etc... place in a decimal number.

He has shown how to shift the second value (the "tens" place) and multiply it by 10.
He has shown how to isolate the first value ( the "units" place) and add it to the shifted value...

Can you see how you might get the thousands place? That's right: you shift it to the right 8 bits...
And what about the 10-thousands value? Right again: you shift it to the right 12 bits...
and so on, and so on...
once you have each value isolated, you multiply it by the corresponding value it represents, like in the above example.

Then you add them all together, and tah dah! You have your value...

It's really quite easy, but you must understand the concept BEFORE you attempt to code it yourself...
Thu Jun 23 2011, 12:22 pm
#7
Thank You DAVE,

Could you explain me in Assembly language because am getting very much confusion there...


Sharath
Thu Jun 23 2011, 05:58 pm
#8
@ sharath411
logic is same as in asm as well as in c
Thu Jun 23 2011, 09:00 pm
#9
Yes, the logic is the same. Also, if it's the syntax of assembly that you are having a problem with, you can always write it in C, and then compile it, and have a look at the assembly file that is generated by the compiler to see exactly how it's done in assembly... just a suggestion.
Fri Jun 24 2011, 01:30 am
#10
Doing this in 8051 assembly is actually quite complicated and tedious.
Are you sure you have to do it all ,what is it for ?

Basically you need to split the 3 bcd bytes into 6 single bytes containing 0-9
Create a 3 byte final total.
Multiply the 6 bytes by an increasing power of ten 1,10,100,1000,10000,100000
Add the result of each multiplication to the final total.

The heart of your routine will be a subroutine that can multiply an 8 bit value
by a 16 or 24 bit value.

Obviously you don't actually multiply by 1, and by multiplying by ten first you can
get away with 8 bit by 16 bit multiplication.


[ Edited Sat Jun 25 2011, 02:04 am ]

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Astorne
Tue Apr 16 2024, 08:52 pm
Williamjaf
Tue Apr 16 2024, 12:25 pm
best_yyPa
Tue Apr 16 2024, 09:42 am
ErnestoExpop
Tue Apr 16 2024, 02:57 am
Jamesclepe
Mon Apr 15 2024, 11:10 am
Aliciaelora
Mon Apr 15 2024, 07:59 am
btaletvpcu
Mon Apr 15 2024, 04:36 am
UbvpwcTib
Mon Apr 15 2024, 03:13 am