Hello there,
I made a simple hex calculator recently because i needed one for some large hex numbers mostly, and it also does some binary stuff. For example, it can turn a very large hex number like:
0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
into BCD or if you want to call it just a 'decimal' number. The number is then converted to string for display.
What it does NOT have yet, is a BCD to binary (or hex) converter, and i found that it would be convenient to have this also. This would take a decimal (or BCD as it is called also) number like this:
341001922204623546932120
and convert it into either hex or binary.
There is a catch here though. I dont want to have to create a base 10 number cruncher if i dont have to. To convert BCD to binary a typical technique is to repeatedly divide by 2 to get the binary number. For example, say we have a BCD number "14" and we want to convert to binary. It would go like this:
14/2=7 with remainder r=0, so we write "0",
7/2=3 with r=1 so we write "1",
3/2=1 with r=1, so we write "1",
1/2=0 with r=1, so we write "1",
so the entire conversion is (writing all the results from the bottom up):
1110
which of course is equal to decimal 14.
This is great and fantastic and all that, but what this algorithm requires is a math number cruncher that can work in decimal, at least so it can divide by 2. For example a larger number would require a fully implemented base 10 cruncher for dividing by 2:
9999999999999999/2=4999999999999999, r=1, so first binary digit is '1'.
Note this requires the ability to divide by 2 in base 10, which is not available yet and i would like to avoid this if possible.
What is available:
N digit hex calculations, four banger: add, subtract, multiply, divide.
N digit binary calculations, four banger: add, subtract, multiply, divide.
N digit shifts left or right.
Note again there is no "N digit decimal calculations" of any kind except for values less than 2^16.
So the question here is, does anyone know of any algorithm that can convert BCD to binary (or to hex) without requiring a BCD number cruncher, and hopefully using a hex or binary calculation only?
The numbers will come in as a string such as:
"314529"
and of course this can be converted to BCD no problem by converting each number in turn to end up with:
0011 0001 0100 0101 0010 1001
if that helps at all.
If there is no other way, then maybe your best decimal divide by 2 algorithm.
Hey, thanks
I made a simple hex calculator recently because i needed one for some large hex numbers mostly, and it also does some binary stuff. For example, it can turn a very large hex number like:
0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
into BCD or if you want to call it just a 'decimal' number. The number is then converted to string for display.
What it does NOT have yet, is a BCD to binary (or hex) converter, and i found that it would be convenient to have this also. This would take a decimal (or BCD as it is called also) number like this:
341001922204623546932120
and convert it into either hex or binary.
There is a catch here though. I dont want to have to create a base 10 number cruncher if i dont have to. To convert BCD to binary a typical technique is to repeatedly divide by 2 to get the binary number. For example, say we have a BCD number "14" and we want to convert to binary. It would go like this:
14/2=7 with remainder r=0, so we write "0",
7/2=3 with r=1 so we write "1",
3/2=1 with r=1, so we write "1",
1/2=0 with r=1, so we write "1",
so the entire conversion is (writing all the results from the bottom up):
1110
which of course is equal to decimal 14.
This is great and fantastic and all that, but what this algorithm requires is a math number cruncher that can work in decimal, at least so it can divide by 2. For example a larger number would require a fully implemented base 10 cruncher for dividing by 2:
9999999999999999/2=4999999999999999, r=1, so first binary digit is '1'.
Note this requires the ability to divide by 2 in base 10, which is not available yet and i would like to avoid this if possible.
What is available:
N digit hex calculations, four banger: add, subtract, multiply, divide.
N digit binary calculations, four banger: add, subtract, multiply, divide.
N digit shifts left or right.
Note again there is no "N digit decimal calculations" of any kind except for values less than 2^16.
So the question here is, does anyone know of any algorithm that can convert BCD to binary (or to hex) without requiring a BCD number cruncher, and hopefully using a hex or binary calculation only?
The numbers will come in as a string such as:
"314529"
and of course this can be converted to BCD no problem by converting each number in turn to end up with:
0011 0001 0100 0101 0010 1001
if that helps at all.
If there is no other way, then maybe your best decimal divide by 2 algorithm.
Hey, thanks