plain/devtools home

Number base converter

Type a number in any base and see it in binary, octal, decimal and hex at once, plus how it looks as a signed or unsigned machine integer.

tool 17 of 21 []
all shortcuts ?

number-basesampless sample

never leaves your browser

How to use it

  1. Choose the base your number is written in, then type it. Prefixes 0x, 0b and 0o are accepted when they match the base, and underscores or spaces are ignored.
  2. The results show the same value in binary, octal, decimal and hex, grouped for reading, plus one custom base of your choice from 2 to 36.
  3. The two's complement table shows how the value is stored in 8, 16, 32 and 64 bits, signed and unsigned. A cell is blank when the value does not fit.
  4. Values are arbitrary precision (BigInt), so you can paste a 256-bit hash fragment without losing digits.

Why hex and binary line up

Sixteen is two to the fourth power, so one hex digit is exactly four bits and two hex digits are one byte. That is why memory addresses, colors (#ff5f1f is three bytes) and hash outputs are written in hex: the grouping matches the hardware. Octal does the same with three bits per digit, which is why Unix file modes such as 755 are octal.

Negative numbers in nearly every modern CPU use two's complement. To negate a value, invert the bits and add one. The same bit pattern is read as -1 when the top bit is treated as a sign and as 255 when it is not, which is why 0xFF means different things in a signed and an unsigned byte.

JavaScript numbers are 64-bit floats and are only exact for integers up to 2^53 - 1, so this tool uses BigInt for the conversion. Bitwise operators in JavaScript also truncate to 32 bits, a frequent source of surprise when you check a result by hand.

The first 16 values in each base

DecimalBinaryOctalHex
0000000
1000111
2001022
3001133
4010044
5010155
6011066
7011177
81000108
91001119
10101012A
11101113B
12110014C
13110115D
14111016E
15111117F

Generated by code when the page is built. Each hex digit is exactly four binary digits.

Examples

Select an example to load it into the tool.

  • 255 decimal255
  • 0xFF hex0xFF
  • Negative byte-1
  • Binary 1010_01010b1010_0101

Frequently asked questions

How do I convert hex to decimal?

Choose input base 16, type the hex digits (0x is optional) and read the decimal row. By hand, multiply each digit by a power of 16 and add: 0xFF is 15 times 16 plus 15, which is 255.

What is the largest number it handles?

There is no fixed limit. BigInt grows as needed, so only your browser memory and patience limit it. The two's complement table covers 8 to 64 bits and leaves a cell blank when the value does not fit.

Does it handle fractions?

No. It converts integers only. Floating point has its own binary layout (IEEE 754), which is a different conversion.

Why do bases above 10 use letters?

After 9, digits continue as a, b, c and so on. Base 16 uses a to f. Base 36 uses all ten digits and all 26 letters, the highest base this tool offers.

Is anything uploaded?

No. The conversion happens in this tab. The test suite fails the build if this tool contains a network call.

Sources

Related tools

esc
↑↓ move↵ open? all shortcuts

Keyboard shortcuts

Cmd or Ctrl shortcuts always work.
Everywhere
Everywhere
Open the command palette
CtrlK
Open the palette (outside a text field)
/
Show these shortcuts
?
Toggle light and dark theme
t
Go home
gh
Go to all tools
gt
On a tool page
On a tool page
Run the main action
Ctrl↵
Copy the output
c
Load the next sample
s
Focus the input
i
Leave a text field
Esc
Previous or next tool
[]
In the palette
In the palette
Move the selection
↑↓
Open the selected item
↵
Close
Esc