Supports radix conversion for integers of any bit length. If you need to convert integers, use this.
Radix, as the name suggests, is the method of carrying over when counting. For example, decimal is base ten, meaning it carries over every ten; binary is base two, carrying over every two, and so on.
The most commonly used in our daily lives is decimal. Other commonly used radix units include binary, octal, and hexadecimal.
Decimal is the most commonly used radix unit, passed down since our monkey ancestors. This is because everyone has ten fingers, and naturally, fingers were used as human counters.
Decimal is easy to understand. It uses ten Arabic numerals from 0 to 9, carrying over every ten.
Binary is represented by two digits 0 and 1, carrying over every two. For example, in binary, 1 plus 1 equals 2, which carries over to become binary 10.
Binary is commonly used in computers because the physical structure of computers uses high and low voltages, which can be represented by 0 and 1.
Octal is made up of eight digits from 01234567, carrying over every eight. The calculation process is similar to binary.
Hexadecimal consists of sixteen characters from 0123456789abcdef. Hexadecimal values generally have a 0x prefix, such as 0x8a, representing the hexadecimal value 8a.
So how do you calculate to convert a number to another radix? Let's consider converting a decimal to N radix and converting N radix to decimal (N can be any radix, such as 2, 8, or 16).
Converting Decimal Value to N Radix
For example, to convert the decimal number 19 to binary using the above formula, the steps are
Converting base N values to decimal
For example, to convert the binary value 1101 to decimal, the steps are
To convert between other bases, use the above method to first convert to decimal, then to the target base