User manual · Calculations

Hexadecimal calculator: hex math, bases and bitwise

Use a hexadecimal calculator: add, subtract, multiply and divide hex with carries shown, convert hex to binary, octal and decimal, and run bitwise operations.

By Hira Noor, mathematicianUpdated
Try
Input format

In the input format chosen above. A minus sign means two’s complement; spaces between digit groups are fine.

In the same format as A.

Word size
Read numbers as

Result

FF + 1 (16-bit): 0100

FF + 1 (16-bit)

0100

256 in decimal (unsigned)

Binary
0000 0001 0000 0000
Hexadecimal
0100
Octal
400
Decimal (unsigned)
256
Decimal (signed, two’s complement)
256
True result (no wrapping)Fits in 16 bits (unsigned)
256
Unsigned overflow (carry)
No
Signed overflow
No
Bits set to 1
1

A + B gives 0000 0001 0000 0000 in 16 bits: 256 unsigned, and the same signed.

A + B in a 16-bit word
ValueBinaryHexUnsignedSigned
A0000 0000 1111 111100FF255255
B0000 0000 0000 0001000111
Result0000 0001 0000 00000100256256
Step-by-step working (3 steps)
  1. Write the inputs as 16-bit patterns

    A = 255 → 0000 0000 1111 1111; B = 1 → 0000 0000 0000 0001. (Converted from hexadecimal.)

  2. Add column by column

    Starting from the right, 1 + 1 = 10 in binary: write 0 and carry 1. 0000 0000 1111 1111 + 0000 0000 0000 0001 = 0000 0001 0000 0000. The carries out of each column were 0000 0000 1111 1111.

  3. Read the result

    The top bit is 0, so the pattern means 256 whether it is read as signed or unsigned.

This is the binary calculator, started with this page’s first example. Its own page adds more presets, the formulas and worked examples.

Short answerThe hex calculator above is ScientifiCalc’s binary calculator with Input format set to Hex, and it opens with FF + 1 = 0100 (256) as a 16-bit sum. Type two hex numbers, upper or lower case and with or without 0x, then pick add, subtract, multiply, divide, AND, OR, XOR, NOT or a shift. Every result is shown in hex, binary, octal and decimal, signed or unsigned, at 8, 16, 32 or 64 bits, with the working under it. To convert one number between bases, use the number base converter.

Try the worked examples from this page in one click: FF + 1, 3A7 + 1C9, 1A3 − B7, 1F × 1A, FF ÷ 7 and F0F0 AND 0FF0.

Hex digits and their binary nibbles

Hexadecimal is base 16. It uses the digits 0 to 9 and then the letters A to F for the values 10 to 15, in upper or lower case. Each hex digit stands for exactly four bits, called a nibble, which is why programmers write memory addresses, color codes such as #FF8800 and byte values in hex. Keep this table next to any hex calculation.

Every hexadecimal digit with its decimal, binary and octal value
HexDecimalBinary (4 bits)Octal
0000000
1100011
2200102
3300113
4401004
5501015
6601106
7701117
88100010
99100111
A10101012
B11101113
C12110014
D13110115
E14111016
F15111117

Hex arithmetic: worked examples with carries and borrows

Hex arithmetic follows the same column rules as decimal, except that a column overflows at 16 instead of 10. When a column adds up to 16 or more, write the amount above 16 and carry 1. When a column cannot subtract, borrow 1 from the next column, which adds 16 to the current one. Each example below opens in the calculator with the same numbers.

Addition: FF + 1 = 100 and 3A7 + 1C9 = 570

  1. FF + 1: F + 1 = 16, write 0 and carry 1

    16 is exactly one more than F, so the column shows 0 and the next column gets a carry.

  2. F + 0 + carry 1 = 16, write 0 and carry 1

    The second column overflows the same way, and the carry moves into a new third column, giving 100. Check: 255 + 1 = 256, and 100 in hex is 1 × 16² = 256.

  3. 3A7 + 1C9: 7 + 9 = 16, write 0 and carry 1

    The ones column is exactly 16.

  4. A + C + 1 = 10 + 12 + 1 = 23 = 16 + 7, write 7 and carry 1

    Subtract 16 from the column total to get the digit.

  5. 3 + 1 + 1 = 5, so the sum is 570

    Check: 935 + 457 = 1,392 = 5 × 256 + 7 × 16. Run 3A7 + 1C9.

Subtraction with a borrow: 1A3 − B7 = EC

  1. 3 − 7 cannot be done, so borrow: 3 + 16 − 7 = 12 = C

    The A in the next column drops to 9.

  2. 9 − B = 9 − 11 cannot be done, so borrow again: 9 + 16 − 11 = 14 = E

    The 1 in the third column drops to 0.

  3. 0 − 0 = 0, so the difference is EC

    Check: 419 − 183 = 236 = 14 × 16 + 12. Run 1A3 − B7.

Multiplication and division: 1F × 1A = 326 and FF ÷ 7 = 24 remainder 3

Multiply hex the way you multiply decimal: one partial product per digit, then add. For 1F × 1A, the A digit gives 1F × A = 136 (31 × 10 = 310), the 1 digit gives 1F shifted one place, 1F0 (496), and 136 + 1F0 = 326, which is 806 in decimal. Run 1F × 1A.

Hex division keeps whole numbers and gives a remainder. FF ÷ 7 is 255 ÷ 7 = 36 remainder 3, and 36 is 24 in hex, so the answer is 24 remainder 3. Check in decimal: 36 × 7 + 3 = 255, which is FF. Run FF ÷ 7.

The four hex arithmetic examples, checked in decimal
HexResult (hex)Same sum in decimal
FF + 1100255 + 1 = 256
3A7 + 1C9570935 + 457 = 1,392
1A3 − B7EC419 − 183 = 236
1F × 1A32631 × 26 = 806
FF ÷ 724 remainder 3255 ÷ 7 = 36 remainder 3

Choose a word size that fits the answer

The calculator works in a fixed number of bits, like a processor register. FF + 1 at 8 bits shows 00 with a carry out of the top bit, because 256 needs 9 bits; at 16 bits it shows 0100. If a result looks wrong, check the Unsigned overflow line and pick a larger word size.

How to convert hex to binary, octal and decimal

Hex to binary is a direct lookup: replace each hex digit with its four bits from the table above. 3A7 becomes 0011 1010 0111, and 2F becomes 0010 1111. Binary to hex works in reverse: split the bits into groups of four from the right, pad the leftmost group with zeros, and read each group as one hex digit, so 1101101 becomes 0110 1101 = 6D.

Octal uses groups of three bits instead of four. To turn 3A7 into octal, write the binary 001 110 100 111 in threes and read each group: 1647. Hex to decimal adds each digit times its power of 16: 3A7 = 3 × 256 + 10 × 16 + 7 = 935. Decimal to hex divides by 16 and reads the remainders from the last to the first:

  1. 935 ÷ 16 = 58 remainder 7

    The first remainder is the rightmost hex digit.

  2. 58 ÷ 16 = 3 remainder 10, which is A

    Remainders from 10 to 15 become the letters A to F.

  3. 3 ÷ 16 = 0 remainder 3

    The quotient is now 0, so stop.

  4. Read the remainders upward: 3A7

    The same repeated division works for any base: divide by 2 for binary or by 8 for octal.

The same values in four bases
DecimalBinaryOctalHexadecimal
10101012A
45101101552D
25511111111377FF
256100000000400100
935111010011116473A7
65,5351111111111111111177777FFFF

The number base converter does these conversions for any base from 2 to 36 and shows each digit times its power. It accepts the 0x, 0b and 0o prefixes that programming languages use, spaces and underscores between digit groups, and lowercase letters. Letters that are not digits in the chosen base, such as G in hex or 2 in binary, are reported as input errors rather than ignored.

Negative hex numbers and two’s complement

Computers store signed integers in a fixed number of bits using two’s complement. With n bits, a negative number −x is stored as 2ⁿ − x, so the leftmost bit acts as the sign bit. An 8-bit value covers −128 to 127 (hex 80 to 7F), a 16-bit value −32,768 to 32,767 (8000 to 7FFF), and in general n bits cover −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1.

To find the 8-bit pattern of −5, write 5 as 00000101, invert every bit to get 11111010, then add 1: 11111011, which is FB in hex and 251 if read as unsigned. At 16 bits the same number is FFFB. A hex pattern alone does not say whether it is signed, so choose the bit width and the signed or unsigned reading that match your program or hardware. In the binary calculator, choose Signed and add 0 to −5 to see the pattern FB with its signed and unsigned readings.

Bitwise operations: AND, OR, XOR, NOT and shifts

Bitwise operators work on each bit position separately, which makes the binary calculator a bitwise operations calculator as well. In hex, every digit maps to its own four bits, so you can often work one hex digit at a time. The table uses 12 (hex C, binary 1100) and 10 (hex A, binary 1010).

Bitwise operations on 12 (C) and 10 (A)
OperationRule for each bitBinaryHexDecimal
C AND A1 only if both bits are 1100088
C OR A1 if either bit is 11110E14
C XOR A1 if the bits differ011066
NOT C (8 bits)Every bit flipped11110011F3243 unsigned, −13 signed
5 shifted left by 2Bits move left, zeros fill in101001420 (5 × 2²)
20 shifted right by 2Bits move right, the lowest bits are dropped10155 (20 ÷ 2², rounded down)

Masks are the everyday use: F0F0 AND 0FF0 = 00F0 keeps only the bits set in both, and the calculator’s preset shows it bit by bit. For negative numbers, a right shift can fill the new leftmost bits in two ways. An arithmetic shift copies the sign bit, so −20 shifted right by 2 is −5. A logical shift fills with zeros, so the 8-bit pattern of −20, 11101100 (EC), becomes 00111011 (3B), which is 59. Check which kind your language or processor uses before comparing results.

Checking a conversion in the scientific calculator

The scientific calculator works in base 10 and has no hex mode, but a few functions reproduce the conversion steps so you can check an answer by hand:

Base-related calculations in base 10
TypeResultMeaning
mod(935, 16) and floor(935/16)7 and 58The last hex digit of 935 is 7; carry on with 58
3*16^2 + 10*16 + 7935Hex 3A7 in decimal
floor(45 / 2^3)545 shifted right by 3 bits
floor(log2(255)) + 18Number of bits needed for 255
2^16 - 165535Largest unsigned 16-bit value, FFFF

Storage sizes use related prefixes: a kilobyte (kB) is 1,000 bytes, while a kibibyte (KiB) is 1,024 bytes, which is 400 in hex. The data storage converter converts between both families.

Frequently asked questions

How do you add hexadecimal numbers?

Add column by column from the right, as in decimal. When a column reaches 16 or more, write the amount above 16 and carry 1 to the next column. For example, 3A7 + 1C9: 7 + 9 = 16 gives 0 carry 1, A + C + 1 = 23 gives 7 carry 1, and 3 + 1 + 1 = 5, so the sum is 570.

What is FF + 1 in hex?

FF + 1 = 100 in hex, which is 255 + 1 = 256 in decimal. Both columns overflow at 16 and carry into a new third digit. In an 8-bit register the result wraps to 00 with a carry out, because 256 needs 9 bits.

How do you convert hex to binary?

Replace each hex digit with its four-bit binary value: 0 = 0000, 9 = 1001, A = 1010, F = 1111. For example, 2F becomes 0010 1111 and 3A7 becomes 0011 1010 0111. To go back, group the bits in fours from the right.

Can I type 0x in front of a hex number?

Yes. The number base converter and the binary calculator both accept a 0x prefix, upper or lower case letters, and spaces or underscores between digit groups, so 0xFF, ff and FF are all read as 255.

Why is NOT 12 equal to 243 and not −13?

Both are correct readings of the same 8-bit pattern 11110011, which is F3 in hex. Read as an unsigned number it is 243; read as a two’s complement signed number it is −13. The bit width and the signed setting decide which one you see.

How many bits do I need to store a number?

A positive whole number n needs floor(log₂ n) + 1 bits, so 255 (FF) needs 8 bits and 256 (100) needs 9. Each hex digit adds 4 bits. Type floor(log2(n)) + 1 in the scientific calculator to check.

Sources and further reading

  1. The Art of Computer Programming, Volume 2: Seminumerical Algorithms, section 4.1, Positional Number Systems, Addison-Wesley (Donald E. Knuth, 1997)
  2. Hacker’s Delight, 2nd edition, chapter 2, Basics (two’s complement and bitwise identities), Addison-Wesley (Henry S. Warren Jr., 2012)
  3. Python documentation: int() and integer literals (0x, 0o, 0b prefixes) (opens in a new tab), Python Software Foundation

Tools on this page

Binary Calculator

Binary addition, subtraction and bitwise operations with steps, at 8 to 64 bits, signed or unsigned.

Hex to Decimal Converter

Hex to decimal with place-value steps, plus binary, octal and any base 2 to 36, fractions included.