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 browser•Nothing is uploaded to a server•Free forever
Decimal
Binary
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:
| Decimal | Binary (8-bit) | What it usually is |
|---|---|---|
| 1 | 0000 0001 | chmod: execute |
| 2 | 0000 0010 | chmod: write |
| 4 | 0000 0100 | chmod: read |
| 6 | 0000 0110 | chmod: read + write (rw-) |
| 7 | 0000 0111 | chmod: read + write + execute (rwx) |
| 64 | 0100 0000 | chmod: owner execute, in the octal 0100 sense |
| 128 | 1000 0000 | the high bit of a byte |
| 192 | 1100 0000 | subnet mask octet for /26 |
| 224 | 1110 0000 | subnet mask octet for /27 |
| 240 | 1111 0000 | subnet mask octet for /28 |
| 248 | 1111 1000 | subnet mask octet for /29 |
| 252 | 1111 1100 | subnet mask octet for /30 |
| 254 | 1111 1110 | subnet mask octet for /31 |
| 255 | 1111 1111 | every 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
- JSON Formatter
- Base64 Encode / Decode
- URL Encoder / Decoder
- Unix Timestamp Converter
- Regex Tester
- UUID Generator (v4 / v7)
- Hash Generator (MD5 / SHA / HMAC)
- JWT Decoder
- Password Generator
- JSON ⇄ CSV Converter
- HTML Entity Encoder / Decoder
- Cron Expression Explainer
- Color Converter
- WCAG Contrast Checker
- All tools on one page (home)