Number base converter
Convert a whole number between binary, octal, decimal, hex and any base up to 36, and see its two's complement bit patterns.
Runs entirely in your browser
Two's complement
| Bits | Bit pattern (hex, binary) | Read as |
|---|
Whole numbers up to 4,096 digits, positive or negative. Fractions are not converted.
How to convert between number bases
- Choose the base your number is written in, or pick Other and enter a base from 2 to 36.
- Type the number. A minus sign is allowed, and a matching
0x,0bor0oprefix is accepted; spaces and underscores are ignored. - Read it in every base below, copy the one you need, and check the two's complement table for fixed-width integers.
How number bases work
A base, or radix, is how many different digits a number system uses. In decimal each position is worth ten times the one to its right; in binary each is worth two times, so 1101 means 8 + 4 + 0 + 1 = 13. Hexadecimal uses sixteen digits, 0 to 9 then A to F, and each hex digit stands for exactly four binary digits, which is why programmers use it as a compact way to write bytes: 255 is FF, or 11111111.
Octal groups binary digits in threes and still appears in Unix file permissions (755 means rwxr-xr-x). Base 36 uses every digit and letter and turns up in short IDs and URL shorteners.
Computers store signed integers in a fixed number of bits using two's complement, where the top bit carries a negative weight. The same bits can therefore mean two different numbers: 11001000 is 200 when read as unsigned and −56 when read as signed. The table under the results shows both readings for the common integer sizes.
Tips
- Turning text into binary bytes rather than a number? Use Text to binary.
- Colour codes like
#1636A3are three hex bytes: read them in the colour converter. - Unix timestamps are plain decimal seconds; convert one with the Unix timestamp converter.
Questions
How large a number can it convert?
Up to 4,096 digits in the input base. The conversion uses exact whole-number arithmetic (BigInt), so very large values such as 2⁶⁴ + 1 = 18446744073709551617 are converted without rounding, unlike calculators that switch to floating point above about 9 quadrillion.
Can it convert fractions such as 0.1?
No. Only whole numbers are converted, and a decimal point is reported as an error rather than silently dropped. Many fractions have no exact form in another base: 0.1 in decimal is a repeating pattern in binary, which is why 0.1 + 0.2 is not exactly 0.3 in most programming languages.
What does two's complement show?
It is how computers store signed integers in a fixed number of bits. A negative number −n is stored as 2 to the power of the bit count, minus n, so −1 in 8 bits is 11111111 (FF). The table shows the bit pattern for 8, 16, 32 and 64 bits, and what that pattern means read as a signed and as an unsigned integer. If the number does not fit in a width, the row says so instead of wrapping it.
Which digits are used above base 10?
Letters, as most programming languages do: A is 10, B is 11 and so on up to Z for 35, which is why base 36 is the highest. Input is accepted in upper or lower case; the uppercase option controls the output.
Why is a digit reported as invalid?
Each base only allows digits below its value: binary allows 0 and 1, octal 0 to 7, hex 0 to 9 and A to F. The error message names the character and its position so you can find a typo, or switch to the base the number is really written in.