What binary is
Binary is the base-2 number system computers use internally. Each digit, called a bit, is either 0 or 1, and each position is worth twice the position to its right: 1, 2, 4, 8, 16 and so on. The decimal number 13, for example, is 8 + 4 + 1, which is written 1101 in binary.
How the conversion works
The standard method is repeated division by two. Divide the number by 2 and note the remainder, then divide the quotient by 2 again, and continue until the quotient is 0. Reading the remainders from the last one to the first gives the binary digits. Here is the tool's own trace for 13:
13 ÷ 2 = 6 remainder 16 ÷ 2 = 3 remainder 03 ÷ 2 = 1 remainder 11 ÷ 2 = 0 remainder 1
Reading the remainders from bottom to top gives 1101. The tool shows the same kind of trace for the number you enter, up to 64 steps.
Negative numbers and two's complement
Computers usually store negative integers in two's complement, which depends on how many bits are available. To find it, write the positive value in the chosen number of bits, flip every bit, and add one. The same bits can mean very different values at different widths, so the tool asks for a bit width when you enter a negative number. The most negative value each width can hold is:
| Bit width | Most negative value |
|---|---|
| 8-bit | -128 |
| 16-bit | -32768 |
| 32-bit | -2147483648 |
| 64-bit | -9223372036854775808 |
A value below that limit is reported as an overflow rather than silently wrapped around.
Large numbers
Whole numbers of any size are converted exactly. Ordinary JavaScript numbers lose precision beyond about 9 quadrillion, so the tool uses arbitrary-precision integers throughout instead.