Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Binary & Hex Calculator

Carries and borrows column by column, two’s complement, overflow flags and bitwise ops.

Free preview, no sign-upIncluded in your pass Pro tool Pro pass: ₹179 / $5.99 for 30 days On this device: nothing is sent
+3 +1 more details No uploadWorks offline once opened Math

Free preview: the names of the flags and of each table’s first rows (up to 3), with the answer, its working and every figure hidden. Locked until you unlock it: download and copy.

Pro pass ₹179 for 30 days or ₹79 for 1 week, one‑time. Pro pass $5.99 for 30 days or $2.99 for 1 week, one‑time. How to unlock

Try before you buy.

  • Free preview: the names of the flags and of each table’s first rows (up to 3), with the answer, its working and every figure hidden.
  • Locked until you unlock it: download and copy.
  • Unlock: Pro pass, ₹179 for 30 days or ₹79 for 1 week, a one-time payment that never renews. Unlock: Pro pass, $5.99 for 30 days or $2.99 for 1 week, a one-time payment that never renews.

Ways to unlock shows how to get the full result.

See passes (opens in a new tab)

Printing this result is locked in the free preview.

Number base

0b, 0o and 0x prefixes override the base. You can also type 1011 + 110 here.

A fixed width wraps around like a processor register and shows the flags.

Try:

Result

— —

    Step by step

      Next steps Done. What next?

      Start over

      A Pro pass unlocks the full result. See passes

      All math calculators & solvers

      About the Binary & Hex Calculator

      Add, subtract, multiply and divide numbers in binary, octal, decimal or hexadecimal and see the working the way it is written by hand: the carries above each column of an addition, the borrows of a subtraction, the partial products of a long multiplication and every line of a long division. Numbers can be as long as you like (up to 4,096 digits), and the answer is checked in decimal.

      Choose a bit width (4 to 256 bits) to work like a processor register: results wrap around, negative numbers are stored in two’s complement, and the carry, overflow, negative and zero flags say what happened. The bitwise mode does AND, OR, XOR, NOT, NAND, NOR and XNOR, logical and arithmetic shifts, and rotations, with every bit lined up. Everything is worked out in your browser.

      How to use it

      1. Choose Arithmetic or Bitwise, then the base the numbers are written in: Bin, Oct, Dec or Hex. A number that starts with 0b, 0o or 0x is read in that base whatever you choose.
      2. Type the two numbers and choose the operation. You can also type a whole calculation such as 1011 + 110, CA AND AC or NOT 0F into the first box.
      3. Leave the bit width on Exact for numbers of any length, or pick 8, 16, 32 or 64 bits (and Signed for two’s complement) to see wrap-around and the flags. Bitwise operations always use a bit width.
      4. Read the answer, the column working, the flags and each step. With a pass, or after unlocking this result, copy the whole working or download it as a text file.

      Examples

      Binary addition with carries
      Input
      1011 + 110
      Result
      10001

      In decimal 11 + 6 = 17. Columns 2, 3 and 4 each carry 1 to the next column, and the last carry becomes a new leading digit.

      Binary subtraction with borrows
      Input
      1101 − 110
      Result
      111

      13 − 6 = 7: the second and third columns each borrow from the column to their left.

      Hexadecimal
      Input
      FF + 1
      Result
      100

      255 + 1 = 256 = 16².

      Binary long division
      Input
      1101 ÷ 11
      Result
      100 remainder 1

      13 ÷ 3 = 4 remainder 1.

      Signed overflow
      Input
      0111 1111 + 1 in 8 bits
      Result
      1000 0000: overflow flag set

      127 + 1 = 128 does not fit in an 8-bit signed number (−128 to 127), so it wraps to −128.

      Bitwise AND
      Input
      CA AND AC (8 bits)
      Result
      88

      1100 1010 AND 1010 1100 = 1000 1000: a bit is 1 only where both are 1.

      Arithmetic right shift
      Input
      1011 0001 >> 3 (8-bit signed)
      Result
      1111 0110

      −79 shifted right by 3 is −10: copies of the sign bit come in on the left, so it is ⌊−79 ÷ 8⌋.

      Common uses

      • Checking binary and hexadecimal arithmetic homework in computer science and digital electronics.
      • Seeing how a processor adds, subtracts and overflows at a fixed width, flag by flag.
      • Working out masks, bit tests and shifts for embedded and systems programming.
      • Learning two’s complement: how negative numbers are stored and why overflow happens.

      Carries, borrows and long division in any base

      In base b each column holds a digit from 0 to b − 1 (Knuth, The Art of Computer Programming, Vol. 2, §4.1). Adding a column gives a total t: write t mod b and carry ⌊t ÷ b⌋ to the next column, so in binary 1 + 1 = 10₂ (write 0, carry 1) and in hex F + 1 = 10₁₆. Subtracting, a column whose top digit is too small borrows one from the column to its left, which is worth b in the column that borrows. Multiplication adds shifted copies of the first number, one for each digit of the second; in binary every digit is 0 or 1, so each partial product is either 0 or the first number shifted left. Long division brings the digits down one at a time and subtracts the divisor as many times as it fits, which in binary is once or not at all.

      Two’s complement and the four flags

      At a width of w bits a register holds 2^w patterns. Read as unsigned numbers they are 0 to 2^w − 1; read as signed (two’s complement) numbers the top bit counts −2^(w−1), so 8 bits hold −128 to 127. To write −x, invert every bit of x and add 1: −5 in 8 bits is 1111 1011. Addition and subtraction are then the same circuit for both readings, and four flags tell the readings apart:

      • Carry (or Borrow for subtraction): the unsigned result did not fit in w bits.
      • Overflow: the signed result did not fit. In an addition this happens exactly when two numbers of the same sign give a result of the other sign, which is when the carry into the top bit differs from the carry out of it.
      • Negative: the top bit of the result is 1.
      • Zero: every bit of the result is 0.

      Bitwise operations, shifts and rotations

      AND gives 1 only where both bits are 1, OR where either is, and XOR where they differ; NAND, NOR and XNOR are the same with every bit inverted, and NOT inverts the bits of one number. A left shift by k moves every bit k places toward the top and fills with zeros, which multiplies by 2^k and keeps the low w bits. A logical right shift fills with zeros and divides an unsigned number by 2^k, rounding down; an arithmetic right shift fills with copies of the sign bit, so it divides a signed number by 2^k rounding toward −∞ (−79 >> 3 = −10). In Java and JavaScript, >> is the arithmetic shift and >>> the logical one. A rotation puts the bits that fall off one end back in at the other.

      Limitations

      • Whole numbers only: there are no binary points (fractions) here.
      • Numbers can have up to 4,096 digits and bit widths go up to 256. The digit-by-digit working is drawn for up to 128 columns; longer numbers still get the exact answer and the decimal check.
      • Exact division rounds the quotient toward 0 and gives the remainder the sign of A, as C and Java do with integers; for floored or Euclidean remainders use the Modulo Calculator.
      • Fixed-width multiplication keeps the low w bits of the product, as a processor’s ordinary multiply does; the full product is shown in the steps.

      Privacy

      On this device: nothing is sent

      Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot.

      Frequently asked questions

      What do I get without a pass?

      Without a pass, Binary & Hex Calculator shows the names of the flags and of each table’s first rows (up to 3), with the answer, its working and every figure hidden. Until you unlock it, the result can’t be downloaded or copied. A Pro, Premium or Ultimate pass, a one-time payment that never renews, unlocks the full result. The pricing page lists the passes and their prices.

      How do you add binary numbers?

      Line the numbers up on the right and add column by column: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1) and 1 + 1 + 1 = 11 (write 1, carry 1). For 1011 + 110 the columns give 1, 0 carry 1, 0 carry 1, 0 carry 1, and the last carry becomes the leading digit: 10001, which is 11 + 6 = 17.

      What is two’s complement?

      The way computers store negative whole numbers: at a width of w bits, −x is stored as 2^w − x. To write it, invert every bit of x and add 1, so −5 in 8 bits is 0000 0101 → 1111 1010 → 1111 1011. The top bit is then 1 for every negative number, and addition works the same for positive and negative numbers.

      What is the difference between the carry flag and the overflow flag?

      The carry flag says the result was too big for w bits read as an unsigned number (255 + 1 in 8 bits). The overflow flag says it was out of range read as a signed number (127 + 1 in 8 bits, which wraps to −128). The same addition can set either, both or neither.

      How do I enter a hexadecimal number?

      Choose Hex and type the digits 0 to 9 and A to F (in either case), or start the number with 0x in any base: 0xFF. Binary numbers can start with 0b and octal ones with 0o, and spaces or underscores between digits are ignored, so 1011 0110 and 1011_0110 are the same number. In Hex, 0B followed by hex digits, such as 0BAD, is read as a hex number.

      What is the difference between >> and >>>?

      Both shift the bits right. >> (arithmetic) fills the empty places with copies of the sign bit, so a negative number stays negative: −79 >> 3 = −10 in 8 bits. >>> (logical) fills them with zeros, so the pattern is treated as an unsigned number: 1011 0001 >>> 3 = 0001 0110.

      Quick answers and tool search

      Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.