Positional numeral system
The value of the number (integer, or rational that has terminating representation in the base ) whose base- representation is is given by: where:
-
is the basis (or radix)
-
is the set of symbols ()
-
is the number of digits to the left of the radix point (the integer part)
-
is the number of digits to the right of the radix point (the fractional part)
-
todo irrational numbers and rational numbers with non-terminating representation
Conversion
Decimal to any base
Converting the integral part
// integer n in base 10 to base b
while n>0
divide n by b to get quotient and remainder;
append remainder to the left of the result;
n=quotient;
Converting the fractional part
// fractional part n in base 10 to base b
while n>0
multiply n by b to get integer part and fractional part;
append integer part to the right of the result;
n=fractional part;
// note: the fractional part may never become zero, stop when the desired precision is reached
Binary–hexadecimal conversion
4 binary digits can be represented by 1 hexadecimal digit
Binary–octal conversion
3 binary digits can be represented by 1 octal digit
Octal–hexadecimal conversion
we can convert octal to binary and then binary to hexadecimal or vice versa