Binary Calculator

Operand 1

Enter a binary number (e.g., 110.001) (no commas, spaces, exponents, fractions, operators)

Operation

Select +, -, *, or /

Operand 2

Enter a binary number (e.g., 110.001) (no commas, spaces, exponents, fractions, operators)

Result

Result is this binary number: Num Digits:

Options:

  • Truncate infinite binary fractions to bits (applies to division only).

(Want to calculate with decimal operands? You must convert them first.)

About the Binary Calculator

This is an arbitrary-precision binary calculator. It can add, subtract, multiply, or divide two binary numbers. It can operate on very large integers and very small fractional values — and combinations of both.

This calculator is, by design, very simple. You can use it to explore binary numbers in their most basic form. It operates on “pure” binary numbers, not computer number formats like two’s complement or IEEE binary floating-point.

How To Use The Binary Calculator

Input

  • Enter one operand in each box. Each operand must be a positive or negative number with no commas or spaces, not expressed as a fraction, and not in scientific notation. Fractional values are indicated with a radix point (‘.’, not ‘,’), and negative numbers are prefixed with a minus sign (“-”).
  • Select an operation (+, – *, /).
  • Change the number of bits you want displayed in the binary result, if different than the default (this applies only to division, and then only when the answer has an infinite fractional part).
  • Click ‘Calculate’ to perform the operation.
  • Click ‘Clear’ to reset the form and start from scratch.

If you want to change an operand, just type over the original number and click ‘Calculate’ — there is no need to click ‘Clear’ first. Similarly, you can change the operator and keep the operands as is.

Output

Besides the result of the operation, the number of digits in the operands and the result is displayed. For example, when calculating 1.1101 * 111.100011 = 1101.1010110111, the “Num Digits” box displays “1.4 * 3.6 = 4.10”. This means that operand 1 has one digit in its integer part and four digits in its fractional part, operand 2 has three digits in its integer part and six digits in its fractional part, and the result has four digits in its integer part and ten digits in its fractional part.

Addition, subtraction, and multiplication always produce a finite result, but division may (in fact, in most cases) produce an infinite (repeating) fractional value. Infinite results are truncated — not rounded — to the specified number of bits. Infinite results are noted with an ellipsis (…) appended to the result, and with an ‘∞’ symbol as the number of fractional digits. For divisions that represent dyadic fractions, the result will be finite, and displayed in full precision — regardless of the setting for the number of fractional bits.

For example, 1/1010 to 24 fractional bits is 0.000110011001100110011001…, with “Num Digits” = “1.0 / 4.0 = 0.∞”; 11/100 = 0.11, with “Num Digits” = “2.0 / 3.0 = 0.2”.

Using the Calculator to Explore Floating-Point Arithmetic

Although this calculator implements pure binary arithmetic, you can use it to explore floating-point arithmetic. For example, say you wanted to know why, using IEEE double-precision binary floating-point arithmetic, 129.95 * 10 = 1299.5, but 129.95 * 100 = 12994.999999999998181010596454143524169921875.

There are two sources of imprecision in such a calculation: decimal to floating-point conversion, and limited-precision binary arithmetic. Decimal to floating-point conversion introduces inexactness because a decimal operand may not have an exact floating-point equivalent; limited-precision binary arithmetic introduces inexactness because a binary calculation may produce more bits than can be stored. In these cases, rounding occurs.

10 and 100 (both decimal) have exact floating-point equivalents (1010 and 1100100, respectively), but 129.95 has only an approximate representation. My decimal to binary converter will tell you that, in pure binary, 129.95 has an infinite repeating fraction:

10000001.111100110011001100110011001100110011001100110011

Rounded to the 53 bits of double-precision, it’s

10000001.11110011001100110011001100110011001100110011

which is 129.94999999999998863131622783839702606201171875 in decimal.

129.95 * 10

129.95 * 10 is calculated as

10000001.11110011001100110011001100110011001100110011 * 1010

which equals 10100010011.0111111111111111111111111111111111111111111

(Try it!)

This is 54 significant bits long, so when it’s rounded to 53 bits it becomes

10100010011.1 = 1299.5

129.95 * 100

129.95 * 100 is calculated as

10000001.11110011001100110011001100110011001100110011 * 1100100

which equals 11001011000010.111111111111111111111111111111111111111011

This is 56 significant bits long, so when it’s rounded to 53 bits it becomes

11001011000010.111111111111111111111111111111111111111

which equals 12994.999999999998181010596454143524169921875

Discussion

To work through this example, you had to act like a computer, as tedious as that was. First, you had to convert the operands to binary, rounding them if necessary; then, you had to multiply them, and round the result.

Limits

For practical reasons, the size of the inputs — and the number of fractional bits in an infinite division result — is limited. If you exceed these limits, you will get an error message. But within these limits, all results will be accurate (in the case of division, results are accurate through the truncated bit position).

Dingbat