Number base converter
Convert numbers between binary, octal, decimal, hex and any base from 2 to 36, with big numbers, two's complement and a bit view.
Code examples
Copy and paste these into your own project. Each one uses only the language's standard library, so there is nothing to install.
const value = 255n
console.log([2, 8, 16].map((base) => value.toString(base)).join(' '))What it does
Converts a number between binary, octal, decimal, hexadecimal and any base from 2 to 36. It keeps every digit of long numbers, shows the two’s complement bit pattern at 8, 16, 32 or 64 bits, and lets you flip single bits.
How to use it
- Type or paste a number in the input field, or in any of the rows.
- Pick the Input base, a Custom base from 2 to 36, and the Bit width.
- Read the other rows, click a bit to flip it, and copy the result.
Examples
255 is 1111 1111 in binary, 377 in octal and FF in hexadecimal.
-1 at 8 bits is 1111 1111 in two’s complement, and FF read as signed at 8 bits is -1 again.
Good to know
- Prefixes
0b,0oand0xare accepted, and so are underscores and spaces between digits. - Numbers are not limited to 64 bits or to 2^53; the bit view only appears when the value fits the chosen width.
- Turn on Read the input as a two’s complement pattern to read
FFas-1instead of 255.
How do negative numbers work in binary?
Computers store a negative number as its two's complement: invert every bit and add one. In 8 bits, -1 is 1111 1111 and -128 is 1000 0000. The same bit pattern reads as 255 or 128 when you read it as unsigned, so the width and the sign matter.
Frequently asked questions
Why does this converter handle numbers above 2^53?
Many converters use floating-point numbers, which lose digits above 9,007,199,254,740,992. This tool uses arbitrary-precision integers, so every digit of a long number is kept.
What do the 0x, 0b and 0o prefixes mean?
They mark the base in source code: 0x for hexadecimal, 0b for binary and 0o for octal. You can type them or leave them out. Underscores and spaces between digits are ignored.
Does this tool send my numbers anywhere?
No. Everything happens in your browser. What you type is never sent to our servers.