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.
| Hex | Decimal | Binary (4 bits) | Octal |
|---|---|---|---|
| 0 | 0 | 0000 | 0 |
| 1 | 1 | 0001 | 1 |
| 2 | 2 | 0010 | 2 |
| 3 | 3 | 0011 | 3 |
| 4 | 4 | 0100 | 4 |
| 5 | 5 | 0101 | 5 |
| 6 | 6 | 0110 | 6 |
| 7 | 7 | 0111 | 7 |
| 8 | 8 | 1000 | 10 |
| 9 | 9 | 1001 | 11 |
| A | 10 | 1010 | 12 |
| B | 11 | 1011 | 13 |
| C | 12 | 1100 | 14 |
| D | 13 | 1101 | 15 |
| E | 14 | 1110 | 16 |
| F | 15 | 1111 | 17 |
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
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.
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.
3A7 + 1C9: 7 + 9 = 16, write 0 and carry 1
The ones column is exactly 16.
A + C + 1 = 10 + 12 + 1 = 23 = 16 + 7, write 7 and carry 1
Subtract 16 from the column total to get the digit.
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
3 − 7 cannot be done, so borrow: 3 + 16 − 7 = 12 = C
The A in the next column drops to 9.
9 − B = 9 − 11 cannot be done, so borrow again: 9 + 16 − 11 = 14 = E
The 1 in the third column drops to 0.
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.
| Hex | Result (hex) | Same sum in decimal |
|---|---|---|
| FF + 1 | 100 | 255 + 1 = 256 |
| 3A7 + 1C9 | 570 | 935 + 457 = 1,392 |
| 1A3 − B7 | EC | 419 − 183 = 236 |
| 1F × 1A | 326 | 31 × 26 = 806 |
| FF ÷ 7 | 24 remainder 3 | 255 ÷ 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:
935 ÷ 16 = 58 remainder 7
The first remainder is the rightmost hex digit.
58 ÷ 16 = 3 remainder 10, which is A
Remainders from 10 to 15 become the letters A to F.
3 ÷ 16 = 0 remainder 3
The quotient is now 0, so stop.
Read the remainders upward: 3A7
The same repeated division works for any base: divide by 2 for binary or by 8 for octal.
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 10 | 1010 | 12 | A |
| 45 | 101101 | 55 | 2D |
| 255 | 11111111 | 377 | FF |
| 256 | 100000000 | 400 | 100 |
| 935 | 1110100111 | 1647 | 3A7 |
| 65,535 | 1111111111111111 | 177777 | FFFF |
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).
| Operation | Rule for each bit | Binary | Hex | Decimal |
|---|---|---|---|---|
| C AND A | 1 only if both bits are 1 | 1000 | 8 | 8 |
| C OR A | 1 if either bit is 1 | 1110 | E | 14 |
| C XOR A | 1 if the bits differ | 0110 | 6 | 6 |
| NOT C (8 bits) | Every bit flipped | 11110011 | F3 | 243 unsigned, −13 signed |
| 5 shifted left by 2 | Bits move left, zeros fill in | 10100 | 14 | 20 (5 × 2²) |
| 20 shifted right by 2 | Bits move right, the lowest bits are dropped | 101 | 5 | 5 (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:
| Type | Result | Meaning |
|---|---|---|
mod(935, 16) and floor(935/16) | 7 and 58 | The last hex digit of 935 is 7; carry on with 58 |
3*16^2 + 10*16 + 7 | 935 | Hex 3A7 in decimal |
floor(45 / 2^3) | 5 | 45 shifted right by 3 bits |
floor(log2(255)) + 1 | 8 | Number of bits needed for 255 |
2^16 - 1 | 65535 | Largest 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.