This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Long Hex ASCII string to decimal ASCII


Using the C51 tools, I am trying to convert a long Hex number, entered as an ASCII string, to its decimal equivalent.
For example:
the string could be:
"ABCDEF1234565"
And I would need to convert to the string:
"188900967593046"

The problem I have found is that since there does not seem to be a true 'double' variable type, I cannot do a direct conversion of the number. Which would consist of converting the ASCII hex to a variable, and then printing it out as decimal.

I have tried several methods, but cannot get past needing variable storage larger than 32bits.

Any suggestions on how to achieve this would be greatly appreciated...

Thanks!

David Marten

Parents
  • C51 does not have built-in features for dealing with very large numbers and all programming languages will have a limit at some point. You seem to need to be able to deal with 64-bit numbers - perhaps larger.

    Your best bet is probably to convert your ASCII string value to an internal binary representation and then convert that binary back to decimal. You may consider storing your binary representation as an array of 64 bytes - one for each bit.

    In answer to another question, I produced a binary to decimal conversion function for 38-bit values. The method is easily adaptable to larger numbers of bits.

    The method is not efficient, but it is easy to implement.

    See:

    http://www.keil.com/forum/msgpage.asp?MsgID=3389

    Have fun.

Reply
  • C51 does not have built-in features for dealing with very large numbers and all programming languages will have a limit at some point. You seem to need to be able to deal with 64-bit numbers - perhaps larger.

    Your best bet is probably to convert your ASCII string value to an internal binary representation and then convert that binary back to decimal. You may consider storing your binary representation as an array of 64 bytes - one for each bit.

    In answer to another question, I produced a binary to decimal conversion function for 38-bit values. The method is easily adaptable to larger numbers of bits.

    The method is not efficient, but it is easy to implement.

    See:

    http://www.keil.com/forum/msgpage.asp?MsgID=3389

    Have fun.

Children