Outside the binary 01010, octal 01122, decimal integer 1234 and hexadecimal 0xFF, does any one have any idea or trick how to build a new number format? For example, 0x11AEGH has it’s range from 0 – 9 to A – H. I’m going to build password generator, so it would be very helpful if anyone can put something on it that might help.
Firstly, Is there any function which can do this? Basically I want to convert 0x11AEGH to binary, octal, integer and so on…
Formatting a number in an N-ary system requires two things: an alphabet, and an ability to obtain results of integer division + the remainder.
Consider formatting a number in a base-26 system using the Latin alphabet. Repeatedly obtain the remainder
Rof division by 26, pick letter numberR, and add it to the front of the number that you are formatting. Integer-divide the number by 26, and use it in the next step of the algorithm. Stop when you reach zero.For example, if you print
1234in base-26, you can do it like this:M; 1234/26 is 47V; 47 / 26 is 1B. 1 / 26 is zero; stop.So
1234in base-26 isBVM.To convert back, start from the front, and sequentially subtract the designated “zero” (
Ain case of the above example) from each digit, like this:B–Ais 1. Result is1V–Ais 21. Result is 1*26+21, which is 47M–Ais 12. Result is 47*26+12, which is 1234.