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 browserNothing is uploaded to a serverFree forever

Binary

Decimal

Copied!

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.

What each bit position is worth
BitValue if set
01
12
24
38
416
532
664
7128
8256
101024
124096
1532768
1665536
201048576
2416777216
312147483648
324294967296
47140737488355328
524503599627370496
539007199254740992
624611686018427387904
639223372036854775808

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