I decided to wrap all functionality in static library class called IntegerBaseConverter.Īt hearth of the class lay two simple algorithms. After deciding to use BigInteger to represent decimal representation of the number, conversion can be performed truly for number of any size. Only limit is the size of available memory. It allows to create and manipulate an arbitrary large integer numbers. Net Framework 4.0 introduced new structure: BigInteger.
#BASE CONVERTER FULL#
"No size limit" - this promise is very easy to full fill. Point is, that we are able to express numbers with written in numeral systems with very large base. Perhaps Chinese characters? Other options are: use graphical objects for characters or colors or mixture of ideas mentioned above.
#BASE CONVERTER HOW TO#
There is no problem to find 64 (or even little more) distinct printable characters in English based character set, but how to write base-x numbers where x is much greater than 64? One thing comes to mind: use Unicode character set for non-English language. There is only one "but." To express the number as base-x representation we need to use x distinct characters to represent digits within the number. "Any base" - I said "any base" because there is nothing what in theory prevents us from encoding numbers using high base numbers. Do not set limits to the size of the number.īoth statements are rather bold and sound unfeasible so they deserve a few words of explanation:.Convert integer number from any base representation to another base representation.What I've decided to have is a library class that allows to: Truth is that to deal with numbers written in different positional numeral systems you need to have tools to help translate numbers from one base to another.Ĭonvert.ToString(int number, int base) allows only to convert decimal representation of an integer to a different base only if the base is 2, 8, 10 or 16, And of course it can deal only with 32-bit integers. It's much shorter than the corresponding binary representation, but I bet you - it's not easy to tell what this number really represents. The same decimal number 1,234,567,890 expressed as hexadecimal looks like: 499602D2. Hexadecimal (base 16) system comes to rescue and makes numbers shorter. The only problem is that numbers expressed as binary make quite long strings for large numbers and they are not easy to read. The binary nature of computer storage, size of byte - elementary storage unit, makes binary (base 2) system natural when dealing with computers. In everyday life we are usually satisfied with the base 10 numeral system, where we can express any number using 10 symbols (digits): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.īut the computer world is quite different.
If you are a programmer you know different positional numeral systems and deal with them on a daily basis.