Binary to Decimal
Bits in, a decimal number out — at any length, and with an honest answer to the question a bit string cannot answer on its own: is that leading 1 a value or a sign?
Runs 100% in your browser•Nothing is uploaded to a server•Free forever
Binary
Decimal
Reading binary as a decimal number
Binary is base 2, so every column is worth twice the one to its right, counting from zero on the far right. Add up the columns that hold a 1 and you have the decimal value: 1101 is 8 + 4 + 1 = 13. That is the whole algorithm, and it is the same one whether the number is four bits or sixty-four.
Bit positions are numbered from the right starting at zero, so "bit 7" is the eighth column and worth 128. That numbering is what documentation means when it says a flag lives "in bit 12", and getting it off by one is the classic way to read a status register wrong.
| Bit | Value if set |
|---|---|
| 0 | 1 |
| 1 | 2 |
| 2 | 4 |
| 3 | 8 |
| 4 | 16 |
| 5 | 32 |
| 6 | 64 |
| 7 | 128 |
| 8 | 256 |
| 10 | 1024 |
| 12 | 4096 |
| 15 | 32768 |
| 16 | 65536 |
| 20 | 1048576 |
| 24 | 16777216 |
| 31 | 2147483648 |
| 32 | 4294967296 |
| 47 | 140737488355328 |
| 52 | 4503599627370496 |
| 53 | 9007199254740992 |
| 62 | 4611686018427387904 |
| 63 | 9223372036854775808 |
A leading 1 does not mean negative
This is the single most common mistake made with binary. Whether the top bit means "negative" depends entirely on the type the value came from, and a bit string on its own carries no type. 11111111 is 255 if it came out of a uint8_t and −1 if it came out of an int8_t. The bits are identical; only the declared type differs.
So the honest answer needs two pieces of information the bits do not carry: how wide the field is, and whether it is signed. Set both above and this page gives you the signed and the unsigned reading together instead of quietly choosing one. Leave the width off and the value is read as a plain positive number of any length, which is what you want when the binary is a mask, a bitmap or a bignum rather than an integer variable.
Long binary strings stay exact
Sixty-four ones is 18,446,744,073,709,551,615, which is well past the point where a converter built on floating point starts rounding. Paste any length you like here; the arithmetic runs in BigInt, so a 64-bit register value, a 128-bit flag word or a 512-bit key fragment all come back digit-for-digit correct.
Whitespace and underscores between groups are ignored, so binary copied out of a datasheet as 1111 0000 1010 0101 converts without editing.
Next: decimal to binary for the return trip, binary to hex when the string is long enough that hex is easier to read, or the full converter.
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)