Number Base Converter
Convert a whole number between bases 2 and 36. Any size is exact, and you can show the 8, 16, 32 or 64-bit two's complement pattern of a negative number.
Digits 0 to 9 and letters a to z, in any case. One optional minus sign at the start.
| Base | Value |
|---|---|
| 2 (binary) | - |
| 8 (octal) | - |
| 10 (decimal) | - |
| 16 (hexadecimal) | - |
| 36 | - |
How to use
- Type a whole number in the Number box. You may start with one minus sign. The box accepts digits and letters, in any case.
- Leave Input base on auto, or choose a base from 2 to 36. With auto, a prefix of
0x,0oor0bsets hexadecimal, octal or binary, and a number without a prefix is read as decimal. - To see how a computer stores a negative number, pick a Width of 8, 16, 32 or 64 bits.
- Tick Group to split binary and hex digits into fours.
- Read the signed decimal value above the table, and the binary, octal, decimal, hexadecimal and base 36 forms in the table.
Worked examples
| Input | Setting | Result |
|---|---|---|
| 255 | auto | binary 11111111, octal 377, hex ff, base 36 73 |
| 0b1101 | auto | 13 in decimal, hex d |
| zz | base 36 | 1295 in decimal (35 × 36 + 35), hex 50f |
| -1 | 8 bits | pattern 11111111, hex ff, decimal row 255 |
| -100 | 16 bits, grouped | 1111 1111 1001 1100, hex ff9c |
| 127 | 8 bits | 01111111, padded to 8 binary digits |
| 200 | 8 bits | refused: the 8-bit range is -128 to 127 |
Check -100 at 16 bits by hand. Two to the power of 16 is 65,536, and 65,536 − 100 = 65,436. In hex that is ff9c, since 15 × 4096 + 15 × 256 + 9 × 16 + 12 = 65,436.
How it works
The number is read one digit at a time into a BigInt, which holds whole numbers of any size with no rounding. Each digit is worth its value times the base raised to its place. For hexadecimal ff that is 15 × 16 + 15 = 255. The same exact value is then written out in each base, so even a 29-digit decimal number stays exact in every row. Floating-point numbers lose accuracy above about 9 quadrillion, and this tool does not.
value = sum of (digit x base^position)
negative at width w: pattern = value + 2^w
Digits. Base 36 uses 0 to 9 then a to z, and output is lower case. A digit that is not below the base is refused with a message that names it. For example, 9 in base 8 is rejected.
Two's complement. Computers store negative whole numbers in a fixed number of bits. At 8 bits the range is -128 to 127. A negative number is shown by adding 2 to the power of the width, so -1 at 8 bits becomes 256 − 1 = 255, which is 11111111. Binary, octal and hex are padded to the full digit count for the width, while decimal and base 36 are not. When a width is chosen, the decimal and base 36 rows show that unsigned pattern, while the signed value stays above the table.
Where each base is used
- Binary (2) is how hardware stores everything. Each digit is one bit.
- Octal (8) groups bits in threes. Unix file permissions such as 755 are octal.
- Hexadecimal (16) groups bits in fours, so one byte is two hex digits. It is used for colours like #ff8800, memory addresses and hashes.
- Base 36 is the largest base that uses only digits and letters, so it makes short IDs from big numbers.
Common mistakes
- Forgetting the prefix with hex. With auto, ff is not a number. Write 0xff or choose base 16.
- Typing a decimal point. Only whole numbers are supported.
- Choosing a width that is too small. 200 does not fit in 8 signed bits.
- Reading a bit pattern as the signed value. 11111111 is 255 unsigned but -1 in 8-bit two's complement.
- Spaces inside the number. Type the digits without spaces. Use Group only for display.
Frequently asked questions
How do I convert binary to decimal?
Choose base 2 and type the binary digits. For example 1010 gives 10.
How do I convert hex to decimal?
Type 0x before the digits, or set base 16. FF gives 255.
What is the largest number it can handle?
There is no fixed limit besides what your browser can handle, since BigInt has no fixed size.
Why do negative numbers need a width?
Because the minus sign is not stored in bits. A fixed width and two's complement encode the sign.
Is my number sent anywhere?
No. The conversion runs in your browser.
Related tools
- chmod Calculator for octal file permissions.
- Colour Converter for hex colours.
- Hex Dump to see file bytes as hex.
- Unit Converter for data sizes such as MiB and MB.
- All calculators and converters