On this page
How to use the binary calculator
- Convert bases: type a number, pick the base it is in, and read it in binary, octal, decimal and hex. The working shows repeated division (from decimal) or place values (to decimal), plus the grouping shortcut between binary, octal and hex. Fractions like
0.1work too, with a digit limit you choose. - Programmer: choose an 8, 16, 32 or 64-bit word, signed or unsigned, and the base you type A and B in. Pick an operation. Tap any bit of A to flip it.
- IEEE-754 float: choose half, single or double precision and type a decimal to encode it, or a bit pattern such as
0x40490FDBto decode it.
| You type | Read as |
|---|---|
156, -156, 10.625 | A number in the base you picked |
0b1011, 0o17, 0x9C | Binary, octal or hex, whatever base is picked |
1011 0110 or 1011_0110 | Spaces and underscores are ignored |
-5 in the Programmer tab | A value; it is stored in two's complement |
2.5e-3, inf, nan, -0 | Decimal input for the IEEE-754 tab |
Whole numbers are exact at any length, so a 200-digit decimal converts digit for digit. Fractions are exact too: the tool works with the fraction itself, so it can tell you where a binary expansion starts repeating.
Place value, two's complement and floats
In base b each digit is worth a power of b. Binary 10100100 means 1·2⁷ + 1·2⁵ + 1·2² = 128 + 32 + 4 = 164. To go the other way, divide by the base again and again and keep the remainders: they are the digits, last one first. A fraction goes the other way round: multiply it by the base and the whole part of each result is the next digit.
A fraction ends in binary only when its denominator, in lowest terms, is a power of 2. 0.625 = 5/8 ends after three digits. 0.1 = 1/10 has a factor of 5 in the denominator, so its binary digits repeat forever, just as 1/3 does in decimal. Octal and hex are shortcuts for binary: each octal digit is 3 bits and each hex digit is 4 bits, so you can convert by grouping. More in the decimal to binary conversion guide.
Fixed-width words and two's complement
A processor stores whole numbers in words of 8, 16, 32 or 64 bits. Read as unsigned, an 8-bit word holds 0 to 255. Read as signed two's complement, the top bit counts as −128, so the range is −128 to 127. To store −5, invert the bits of 5 (00000101 becomes 11111010) and add 1: 11111011. The same bits mean 251 unsigned, which is why the tool shows both readings. When a true result does not fit the word, the word keeps only the low bits: that is overflow. For unsigned addition the sign is a carry out of the top bit; for signed addition it is two operands of the same sign giving a result of the other sign. See the two's complement walkthrough and bitwise AND, OR and XOR explained.
IEEE-754 floating point
A float stores a sign bit, a biased exponent and a mantissa (the fraction bits). A normal number is (−1)^sign × 1.mantissa × 2^(exponent − bias); the leading 1 is not stored. An exponent field of all zeros means zero or a subnormal number (0.mantissa × 2^(1 − bias)); all ones means infinity or NaN. A decimal that does not fit exactly is rounded to the nearest float, with ties going to the one whose last bit is 0.
| Format | Sign, exponent, mantissa bits | Bias | Largest finite value |
|---|---|---|---|
| Half (16-bit) | 1, 5, 10 | 15 | 65504 |
| Single (32-bit) | 1, 8, 23 | 127 | about 3.4028235 × 10³⁸ |
| Double (64-bit) | 1, 11, 52 | 1023 | about 1.7976931348623157 × 10³⁰⁸ |
Three worked examples
1. Convert 164 to binary and hex
Divide by 2 and keep the remainders:
164 ÷ 2 = 82 r 0, 82 ÷ 2 = 41 r 0, 41 ÷ 2 = 20 r 1, 20 ÷ 2 = 10 r 0,10 ÷ 2 = 5 r 0, 5 ÷ 2 = 2 r 1, 2 ÷ 2 = 1 r 0, 1 ÷ 2 = 0 r 1
Reading the remainders from the bottom up gives 164 = 10100100 in binary. Group the bits in fours from the right, 1010 0100, and each group is one hex digit: 1010 = A and 0100 = 4, so 164 = A4 in hex. In threes, 010 100 100 gives 244 in octal. Check: 10·16 + 4 = 164.
2. 100 + 60 in an 8-bit signed word
In binary, A = 01100100 and B = 00111100. Adding column by column from the right, carries enter columns 3 to 7:
01100100+ 00111100= 10100000
As an unsigned byte, 10100000 is 160, which is right. As a signed byte its top bit is set, so it reads as −96. The true sum, 160, is above the signed limit of 127, so this is signed overflow: two positive numbers gave a negative result. The tool shows the V flag (signed overflow) as yes and the carry out of the top bit as no. Switch the word to 16-bit and the same sum fits.
3. Why 0.1 is not 0.1 in a float
Multiply 0.1 by 2 again and again: 0.2 (digit 0), 0.4 (0), 0.8 (0), 1.6 (1), then 0.6 × 2 = 1.2 (1), and the fraction 0.2 has come back. So 0.1 = 0.00011 in binary, with 0011 repeating forever. A float has to cut it off.
In single precision, 0.1 = 1.6 × 2⁻⁴, so the exponent field is −4 + 127 = 123 = 01111011. The 23 mantissa bits are 10011001100110011001100, and the bits after them start with 1100, more than half a unit in the last place, so the mantissa rounds up to 10011001100110011001101. The result is 0x3DCCCCCD, and the value actually stored is exactly 0.100000001490116119384765625. That is 1.490116119 × 10⁻⁹ more than 0.1. In double precision the stored value is 0.1000000000
Reading the result and common mistakes
- Signed or unsigned. The bits 10100000 are 160 or −96 depending on how you read them. Set the switch to match your course or your C type.
- Arithmetic or logical shift right. −20 is 11101100. Shifting right by 2 arithmetically copies the sign bit in and gives 11111011 = −5. A logical shift brings in zeros and gives 00111011 = 59.
- Hex input to the float tab is bits, not a value.
0x40490FDBis the single-precision pattern of π, 3.1415927410125732421875, not the integer 1078530011. - Big whole numbers in floats. Single precision has 24 bits of precision, so 16777217 is stored as 16777216: it is a tie and rounds to the even neighbour. Half precision tops out at 65504, and anything from 65520 up rounds to infinity.
- Shortest decimal versus stored value. A program prints 0.1 for the float 0x3DCCCCCD because 0.1 is the shortest decimal that reads back to the same bits. The exact stored value is the long one.
The binary, octal and hex calculator guide shows the same conversions on the scientific calculator's base-N mode.
Links that open a problem
The address bar follows your input, and Copy link gives the same address to share.
| Parameter | Example | Meaning |
|---|---|---|
n, from, digits | ?n=255&from=10 | Number, its base (2, 8, 10, 16) and fraction digits |
tab=prog, a, b, op | ?tab=prog&a=100&b=60&op=add | Programmer tab; op is add, sub, mul, div, and, or, xor, not, nand, nor, xnor, shl, shr, sar, rol or ror |
w, s, ib | &w=16&s=s&ib=10 | Word size, signed (s) or unsigned (u), input base |
f, p | ?f=0.1&p=32 | IEEE-754 input and format (16, 32 or 64) |
Embed the Binary Calculator on your website
Teachers, bloggers and course sites can add this tool to any web page for free. Paste the code below into an HTML or embed block (WordPress, Google Sites, Canvas, Moodle, Blogger, Wix). It loads the same tool you see above, without our menus or ads. Please keep the credit line under the frame. Sizes, a live preview and step-by-step guides for each platform are on the calculator widget page.
Frequently asked questions
How do I convert decimal to binary?
Divide the number by 2 again and again and write down each remainder, then read the remainders from the last to the first. For 164 that gives 10100100. The Convert tab shows this table for any whole number.
How do I convert a decimal fraction like 0.1 to binary?
Multiply the fraction by 2 and take the whole part as the next digit, then repeat with what is left. For 0.1 the fractions run 0.2, 0.4, 0.8, 0.6 and back to 0.2, so the binary digits 0011 repeat forever after the first 0.
What is two's complement?
It is how computers store negative whole numbers. To get −x, invert every bit of x and add 1, so −5 in 8 bits is 11111011. The top bit then counts as a negative weight, giving 8-bit signed words a range of −128 to 127.
Why is 0.1 not exact in floating point?
0.1 has a repeating binary expansion, so a float must round it. In single precision the nearest float is 0.100000001490116119384765625, and in double precision it is 0.1000000000
What is the difference between an arithmetic and a logical shift right?
A logical shift fills the empty top bits with zeros. An arithmetic shift fills them with copies of the sign bit, so a negative number stays negative: −20 shifted right by 2 is −5 arithmetically but 59 logically in an 8-bit word.
How do I decode a hex value like 0x40490FDB?
Open the IEEE-754 tab and type it with the 0x prefix. Eight hex digits select single precision; this one has sign 0, exponent 128 (so E = 1) and mantissa 1.57079637050628662109375, which gives 3.1415927410125732421875, the float closest to π.