Decimal to Binary

Decimal in, bits out — zero-padded to 8, 16, 32 or 64 so the columns line up against whatever you are comparing them with.

Runs 100% in your browserNothing is uploaded to a serverFree forever

Decimal

Binary

Copied!

Turning a decimal number into bits

Two methods, same answer. Divide repeatedly by 2 and read the remainders bottom to top, or find the largest power of two that fits, subtract it, and repeat. For 13: 8 fits, leaving 5; 4 fits, leaving 1; 2 does not; 1 fits, leaving 0 — so bits 3, 2 and 0 are set and the answer is 1101. The converter above runs the division form in BigInt, which is why it stays exact for numbers far past what a calculator will hold.

Choose a width or the answer is incomplete

Left to itself, 5 in binary is 101. As a byte it is 00000101. The leading zeros are not decoration — they say how wide the field is, and a bit pattern written without them cannot be lined up against another one. Set a width above and the output is padded to 8, 16, 32 or 64 bits, which is the form you want any time the number is going into a mask, a register or a protocol field.

The numbers that are really bit patterns

A lot of "decimal" numbers in configuration files are bit patterns wearing a decimal disguise, and they only make sense once you see the bits:

Values you are probably converting, and their bits
DecimalBinary (8-bit)What it usually is
10000 0001chmod: execute
20000 0010chmod: write
40000 0100chmod: read
60000 0110chmod: read + write (rw-)
70000 0111chmod: read + write + execute (rwx)
640100 0000chmod: owner execute, in the octal 0100 sense
1281000 0000the high bit of a byte
1921100 0000subnet mask octet for /26
2241110 0000subnet mask octet for /27
2401111 0000subnet mask octet for /28
2481111 1000subnet mask octet for /29
2521111 1100subnet mask octet for /30
2541111 1110subnet mask octet for /31
2551111 1111every bit set

Unix permissions are the clearest example: chmod 755 is three octal digits, each of which is three bits — read, write, execute — so 7 is 111 and 5 is 101. A subnet mask octet is the same idea at eight bits: every mask octet is a run of ones followed by a run of zeros, which is why 192, 224, 240 and 248 are the values you see and 200 is not one of them.

Negative decimals become two's complement

There is no minus sign in a register. Set a width, tick signed, and type −5: you get the two's-complement pattern for that width — 11111011 at eight bits — which is what the hardware would actually hold. Without a width the converter has no field size to complement against, so it keeps the sign and treats the value as plain mathematics instead.

Related: binary to decimal, decimal to hex when the string gets long, and the full converter for every base at once.

More developer tools