/utils

Number Base Converter

Convert integers of any size between binary, octal, decimal and hexadecimal, with prefixes, signs and digit separators.

Type a number, choose the base it is written in, and read it in every common base at once.

Binary 0b
1111 1111
Octal 0o
377
Decimal
255
Hexadecimal 0x
FF

How positional notation works

In base bb, the digits dk…d1d0d_k \dots d_1 d_0 stand for

∑i=0kdi⋅bi.\sum_{i=0}^{k} d_i \cdot b^i .

So 0xFF is 15⋅16+15=25515 \cdot 16 + 15 = 255. Converting to another base repeatedly divides by the new base and collects the remainders.

Input rules

  • Prefixes 0b, 0o and 0x are optional for their bases.
  • A leading + or - sets the sign. Negative numbers are shown with a minus sign, for example -FF, not in two’s complement.
  • Underscores and spaces are ignored, so 1111_0000 is valid.
  • Integers only, with no size limit (the converter uses BigInt).

Further reading

  • D. E. Knuth, The Art of Computer Programming, Volume 2: Seminumerical Algorithms, 3rd ed., Addison-Wesley, 1997.

Full bibliography