How to convert a "big" Hex number (in string format):
EC851A69B8ACD843164E10CFF70CF9E86DC2FEE3CF6F374B43C854E3342A2F1AC3E30C741CC41E679DF6D07CE6FA3A66083EC9B8C8BF3AF05D8BDBB0AA6CB3EF8C5BAA2A5E531BA9E28592F99E0FE4F95169A6C63F635D0197E325C5EC76219B907E4EBDCD401FB1986E4E3CA661FF73E7E2B8FD9988E753B7042B2BBCA76679
to a decimal number (in string format):
166089946137986168535368849184301740204613753693156360462575217560130904921953976324839782808018277000296027060873747803291797869684516494894741699267674246881622658654267131250470956587908385447044319923040838072975636163137212887824248575510341104029461758594855159174329892125993844566497176102668262139513
without using BigInteger
Class (as my application should support machines without .NET Framework 4)?
An easy way would be to use a big number library that supports your version of .NET. I'd recommend GnuMpDotNet, which uses the excellent GMP library. By default it targets .NET 3.5, but you can change that to .NET 2.0 without breaking anything (just remove the references and
using
statement that refer to new things), as it doesn't use anything from .NET 3.5. Here is an example using GnuMpDotNet:Here's a quick-and-dirty implementation that can work with arbitrarily-large numbers. The aim of this implementation is simplicity, not performance; thus, it should be optimized drastically if it's to be used in a production scenario.
Edit: Simplified further per Dan Byström's implementation of the inverse decimal-to-hex conversion:
I just translated Douglas' code into VBA
Also a benchmark at statman.info Hexadecimal Conversion for large numbers
Look at my answer here: https://stackoverflow.com/a/18231860/2521214
worth looking
You can use the IntX library as it should work with .Net 2.0 and up. From the description on the page in regards to
BigInteger
:The license is pretty liberal but worth reading first just to make sure it's okay.
I've not used this library but from a cursory glance at the source code this should be all you need to do
If you don't want to compile the code yourself, you can install it via Nuget.
I just translated Douglas code to JAVA: