Hex Calculator
Perform hexadecimal arithmetic operations and convert between hex, decimal, and binary
Introduction to Hexadecimal System
Hexadecimal (hex) is a base-16 numbering system that uses 16 distinct symbols: the digits 0-9 to represent values zero to nine, and the letters A-F (or a-f) to represent values ten to fifteen. In hexadecimal, A = 10, B = 11, C = 12, D = 13, E = 14, and F = 15.
Each hexadecimal digit represents exactly 4 binary digits (bits), also known as a "nibble." This makes hexadecimal particularly useful for representing binary data in a more compact and human-readable form. For example, the binary number 1010101010 can be represented more compactly as 2AA in hexadecimal.
Why Use Hexadecimal?
- Compact representation of binary data (each hex digit = 4 bits)
- Easy conversion between hex and binary
- Commonly used in computer science, programming, and digital electronics
- Used in memory addresses, color codes (e.g., #FF0000 for red), and file formats
Hex/Decimal Conversion
| Hex | Binary | Decimal |
|---|
| 0 | 0 | 0 |
| 1 | 1 | 1 |
| 2 | 10 | 2 |
| 3 | 11 | 3 |
| 4 | 100 | 4 |
| 5 | 101 | 5 |
| 6 | 110 | 6 |
| 7 | 111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| A | 1010 | 10 |
| B | 1011 | 11 |
| C | 1100 | 12 |
| D | 1101 | 13 |
| E | 1110 | 14 |
| F | 1111 | 15 |
| 10 | 10000 | 16 |
| 14 | 10100 | 20 |
Converting between Decimal and Hex
Hexadecimal uses a positional notation system where each position represents a power of 16. The rightmost position is 16⁰ (1), the next is 16¹ (16), then 16² (256), 16³ (4096), and so on.
Example: Converting Hex to Decimal (2AA)
(2 × 16²) + (A × 16¹) + (A × 16⁰)
= (2 × 256) + (10 × 16) + (10 × 1)
= 512 + 160 + 10
= 682
Example: Converting Decimal to Hex (1500)
Step 1: Largest power of 16 ≤ 1500 is 16² = 256
Step 2: 1500 ÷ 256 = 5 remainder 220 (5 is the value in the 16² place)
Step 3: 256 × 5 = 1280
Step 4: 1500 - 1280 = 220
Step 5: 220 ÷ 16 = 13 remainder 12 (13 is the value in the 16¹ place)
Step 6: 16 × 13 = 208
Step 7: 220 - 208 = 12 (12 is the value in the 16⁰ place)
Step 8: Remember: 10=A, 11=B, 12=C, 13=D, 14=E, 15=F
Step 9: Therefore, 1500 (decimal) = 5DC (hex)
Example: Converting Hex to Decimal (C04)
(C × 16²) + (0 × 16¹) + (4 × 16⁰)
= (12 × 256) + (0 × 16) + (4 × 1)
= 3072 + 0 + 4
= 3076
Hex Addition
Hexadecimal addition works similarly to decimal addition, but you carry when the sum exceeds 15 (F). When adding, if the result in any column is 16 or greater, you subtract 16 and carry 1 to the next column.
Example:
B (11) + 8 = 19 (decimal) = 13 (hex, which is D), carry 1
1 + A (10) + 7 = 18 (decimal) = 12 (hex, which is C), carry 1
1 + 8 + 8 = 17 (decimal) = 11 (hex, which is B), carry 1
Final carry: 1 = 1
Result: 1423 (hex)
Hex Subtraction
Hexadecimal subtraction works similarly to decimal subtraction, but when you need to borrow, you borrow 16 (not 10) from the next column. This is because each position represents a power of 16.
Example:
C (12) - 1 = 11 (B)
D (13) - A (10) = 3
5 - 3 = 2
Result: 23B (hex)
Hex Multiplication
Hexadecimal multiplication can be performed directly in hex, but it often requires converting to decimal for intermediate calculations, especially for larger numbers. The process is similar to decimal multiplication but uses base-16 arithmetic.
Example: FA × 3
3 × A (10) = 30 (decimal) = 1E (hex), write E, carry 1
3 × F (15) + 1 = 45 + 1 = 46 (decimal) = 2E (hex)
Result: 2EE (hex)
Hex Division
Hexadecimal division can be performed using long division in hex, similar to decimal long division. Alternatively, you can convert both numbers to decimal, perform the division, and convert the result back to hex.
Examples:
12 (hex) ÷ 2 = 9 (hex) [18 (decimal) ÷ 2 = 9 (decimal)]
12 (hex) ÷ 3 = 6 (hex) [18 (decimal) ÷ 3 = 6 (decimal)]
12 (hex) ÷ 4 = 4.8 (hex) [18 (decimal) ÷ 4 = 4.5 (decimal) = 4.8 (hex)]
12 (hex) ÷ 5 = 3.C (hex) [18 (decimal) ÷ 5 = 3.6 (decimal) = 3.C (hex)]
12 (hex) ÷ 6 = 3 (hex) [18 (decimal) ÷ 6 = 3 (decimal)]
12 (hex) ÷ 7 = 2.B (hex) [18 (decimal) ÷ 7 ≈ 2.571 (decimal) = 2.B (hex)]
12 (hex) ÷ 8 = 2.4 (hex) [18 (decimal) ÷ 8 = 2.25 (decimal) = 2.4 (hex)]
12 (hex) ÷ 9 = 2 (hex) [18 (decimal) ÷ 9 = 2 (decimal)]
Hexadecimal Multiplication Table
This table shows the product of any two hexadecimal digits from 1 to F, plus 10. Use this table as a reference for hexadecimal multiplication.
| × | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | 10 |
|---|
| 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | 10 |
| 2 | 2 | 4 | 6 | 8 | A | C | E | 10 | 12 | 14 | 16 | 18 | 1A | 1C | 1E | 20 |
| 3 | 3 | 6 | 9 | C | F | 12 | 15 | 18 | 1B | 1E | 21 | 24 | 27 | 2A | 2D | 30 |
| 4 | 4 | 8 | C | 10 | 14 | 18 | 1C | 20 | 24 | 28 | 2C | 30 | 34 | 38 | 3C | 40 |
| 5 | 5 | A | F | 14 | 19 | 1E | 23 | 28 | 2D | 32 | 37 | 3C | 41 | 46 | 4B | 50 |
| 6 | 6 | C | 12 | 18 | 1E | 24 | 2A | 30 | 36 | 3C | 42 | 48 | 4E | 54 | 5A | 60 |
| 7 | 7 | E | 15 | 1C | 23 | 2A | 31 | 38 | 3F | 46 | 4D | 54 | 5B | 62 | 69 | 70 |
| 8 | 8 | 10 | 18 | 20 | 28 | 30 | 38 | 40 | 48 | 50 | 58 | 60 | 68 | 70 | 78 | 80 |
| 9 | 9 | 12 | 1B | 24 | 2D | 36 | 3F | 48 | 51 | 5A | 63 | 6C | 75 | 7E | 87 | 90 |
| A | A | 14 | 1E | 28 | 32 | 3C | 46 | 50 | 5A | 64 | 6E | 78 | 82 | 8C | 96 | A0 |
| B | B | 16 | 21 | 2C | 37 | 42 | 4D | 58 | 63 | 6E | 79 | 84 | 8F | 9A | A5 | B0 |
| C | C | 18 | 24 | 30 | 3C | 48 | 54 | 60 | 6C | 78 | 84 | 90 | 9C | A8 | B4 | C0 |
| D | D | 1A | 27 | 34 | 41 | 4E | 5B | 68 | 75 | 82 | 8F | 9C | A9 | B6 | C3 | D0 |
| E | E | 1C | 2A | 38 | 46 | 54 | 62 | 70 | 7E | 8C | 9A | A8 | B6 | C4 | D2 | E0 |
| F | F | 1E | 2D | 3C | 4B | 5A | 69 | 78 | 87 | 96 | A5 | B4 | C3 | D2 | E1 | F0 |
| 10 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | A0 | B0 | C0 | D0 | E0 | F0 | 100 |