navaja.dev / number-base

Number base converter

Type a number in binary, octal, decimal, hex or any base up to 36 to see it in all the others, with its two's complement bits and how it is stored as a float.

From

Bases
Two's complement
WidthBits (hex)SignedUnsignedCopy
Bits

Click a bit to flip it.

IEEE 754 floating point

How to convert between number bases

Two's complement

Negative integers are stored in two's complement: -1 is 0xff in 8 bits and 0xffffffff in 32. The table shows the bits at every width from 8 to 128 that can hold your number, and what those bits mean as signed and unsigned, so 0xff is 255 unsigned and -1 as an int8. The bit view lets you flip single bits to build masks and flags.

Floating point (IEEE 754)

Every number is also shown as a 64-bit double and a 32-bit float: the hex bits, the sign, exponent and fraction fields, and the exact decimal value the float really stores. That is why 0.1 + 0.2 !== 0.3: 0.1 is stored as 0.1000000000000000055511151231257827…. Paste float bits like 0x3f800000 to see the float they encode (1 as a float32).

Questions

How do I convert hex to decimal?

Type the hex number, with or without 0x, for example ff or 0xff. If it has only digits, pick 16 so it isn't read as decimal. The Decimal row shows 255.

How do I convert decimal to binary?

Type the decimal number. The Binary row shows it grouped in fours, like 1111 1111 for 255. Copy gives the digits without spaces.

How are negative numbers converted?

The base rows show a minus sign, like -0xff. The two's complement table shows the bits a computer stores, like 0xff01 for -255 in 16 bits.

Why does 0.1 never end in binary?

0.1 is 1/10, and 10 has a factor of 5, which binary can't divide evenly, so the digits 0011 repeat forever. Floats keep only 52 or 23 bits of it, which is the rounding error you see in code.

How large can the numbers be?

Up to 4,096 characters. The conversion uses exact big integers, so nothing is rounded except the IEEE 754 float rows.

What do the letters in base 36 mean?

Bases above 10 use a to z for the digits 10 to 35. Hex uses a to f, and base 36 uses the whole alphabet.