Hex string to Dec String

P

PSN

Hi all,
I have tried all types of keywords but was not able to find anything
similar to my question. Anyway, here is my problem:

I like to convert a very big hex string (>64bits) to a decimal based
string .. or may be a very big binary string (>64bits) to a decimal
based string .. Can anyone please suggest how this can be achieved
logically ???

ex: char *pHexStr = "11223344556677889900AABBCCDDEEFF" ==> Decimal
equivalent !!!

Thank you all for your time,

Regards,
P.
 
A

Alf P. Steinbach

* PSN:
Hi all,
I have tried all types of keywords but was not able to find anything
similar to my question. Anyway, here is my problem:

I like to convert a very big hex string (>64bits) to a decimal based
string .. or may be a very big binary string (>64bits) to a decimal
based string .. Can anyone please suggest how this can be achieved
logically ???

ex: char *pHexStr = "11223344556677889900AABBCCDDEEFF" ==> Decimal
equivalent !!!

Create routines

std::string add( std::string const& a, std::string const& b );
std::string decimalFromHexDigit( char const digit );

Then

std::string times2( std::string const& decimalDigits );
std::string times4( std::string const& decimalDigits );
std::string times16( std::string const& decimalDigits );

and then you can walk your hex string from left to right,

std::string decimalFromHex( std::string const& hexDigits )
{
int const n = hexDigits.length();
std::string result = "0";
for( i = 0; i < n; ++i )
{
result = add(
times16( result ), decimalFromHexDigit( hexDigits )
);
}
}

Disclaimer: off-the-cuff code.


Cheers & hth.,

- Alf
 
A

Alan Mackenzie

PSN said:
Hi all,
I have tried all types of keywords but was not able to find anything
similar to my question. Anyway, here is my problem:
I like to convert a very big hex string (>64bits) to a decimal based
string .. or may be a very big binary string (>64bits) to a decimal
based string .. Can anyone please suggest how this can be achieved
logically ???
ex: char *pHexStr = "11223344556677889900AABBCCDDEEFF" ==> Decimal
equivalent !!!

Well, that string is clearly ((16^34 - 1)/15 + 238)/255, which you could
almost work out in your head. ;-)
 
J

Jorgen Grahn

Hi all,
I have tried all types of keywords but was not able to find anything
similar to my question. Anyway, here is my problem:

I like to convert a very big hex string (>64bits) to a decimal based
string .. or may be a very big binary string (>64bits) to a decimal
based string .. Can anyone please suggest how this can be achieved
logically ???

ex: char *pHexStr = "11223344556677889900AABBCCDDEEFF" ==> Decimal
equivalent !!!

Why? I can imagine no need for so gigantic integers (roughly 2.3e+37
according to Python) without doing numerics on it. In which case you
need some bignum library, which (I assume) includes string conversion
routines which solve your problem.

(But of course my imagination has limits).

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top