Sign in to follow this  
_Madman_

Hex conversion

Recommended Posts

Iterate through the string and convert 9 digits at a time. By doing 9, you can be sure you're not overflowing.
Another way would be by converting it yourself, preferably by making a conversion-table.

Share this post


Link to post
Share on other sites
Doing it nine digits at a time will not work. 109 in hex is 0x3B9ACA00 which is not the same as treating it as two nine digit numbers (1 and 0).

If you want to be able to accurately convert numbers that exceed the standard number formats (64/32/etc. bit), then you need to create a set of functions / class to do this. Lucky for you, as a result of another thread, I've written a class to do this and it can be downloaded here. You'll need to write your own hex output routine, but that's really trivial - there's an example of base 10 output that can be changed to base 16, or you can delve into the inner structure and output each char in the stored number as a hex pair.

Skizz

P.S. I don't think there's a quick method for number base conversion other than the brute force approach.

Share this post


Link to post
Share on other sites
Gnu Bignums

Base conversion between bases which are no multiples of each other all work by dividing through the new base and collecting remainders.

In languages with builtin bignums like common lisp it would be a 1-liner.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this