Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Hex string to Dec String

Reply
Thread Tools

Hex string to Dec String

 
 
PSN
Guest
Posts: n/a
 
      02-09-2010
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.
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      02-09-2010
* 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[i] )
);
}
}

Disclaimer: off-the-cuff code.


Cheers & hth.,

- Alf
 
Reply With Quote
 
 
 
 
Alan Mackenzie
Guest
Posts: n/a
 
      02-09-2010
PSN <(E-Mail Removed)> wrote:
> 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 + 23/255, which you could
almost work out in your head.

> Thank you all for your time,


> Regards,
> P.


--
Alan Mackenzie (Nuremberg, Germany).

 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      02-09-2010
On Tue, 2010-02-09, PSN wrote:
> 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

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hex Color Codes - Hex 6 <=> Hex 3 lucanos@gmail.com HTML 10 08-18-2005 11:21 PM
where on the web are the characters for UTF-8 listed in dec or hex value? lkrubner@geocities.com XML 2 05-28-2005 09:05 AM
ANNOUNCEMENT: NYLXS Open House Dec. 6; Perl Classes Dec. 8th J.E./C.Y.Cripps Perl Misc 0 12-03-2004 04:44 PM
Question: HEX <-> DEC constants auto-conversion in C source file? ^_^ C++ 2 01-06-2004 11:55 PM
hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? Bengt Richter Python 6 08-19-2003 07:33 AM



Advertisments