Perform hexadecimal calculations — Add, Subtract, Multiply, or Divide. Also convert between hex and decimal values.
The hexadecimal (hex) number system is a base-16 positional numeral system. It uses sixteen distinct symbols to represent values: the digits 0 through 9 represent values zero to nine, and the letters A through F (case-insensitive) represent values ten through fifteen.
| Hex Digit | Decimal Value | Binary (4-bit) |
|---|
Because each hexadecimal digit maps to exactly 4 binary bits (a "nibble"), hex provides a compact, human-readable representation of binary data. Two hex digits represent one byte (8 bits), so FF = 11111111 = 255. This direct mapping is why hexadecimal is the preferred notation in computing for memory addresses, color codes, MAC addresses, error codes, and low-level programming.
For comparison, the number 255 is written as:
Hex is far more compact than binary and aligns perfectly with byte boundaries, making it indispensable in systems programming, networking, and digital design.
To convert a hexadecimal number to decimal, multiply each hex digit by 16 raised to the power of its position (starting from 0 on the right), then sum all the products. This is called positional notation expansion.
Where each dᵢ is the decimal equivalent of the hex digit at position i.
3B to Decimal2AF to DecimalFFFF to Decimal| Power | Value | Common Name |
|---|---|---|
| 16⁰ | 1 | — |
| 16¹ | 16 | — |
| 16² | 256 | 1 byte max + 1 |
| 16³ | 4,096 | — |
| 16⁴ | 65,536 | 2-byte max + 1 |
| 16⁵ | 1,048,576 | 1 MB |
| 16⁶ | 16,777,216 | 16 MB |
| 16⁷ | 268,435,456 | 256 MB |
| 16⁸ | 4,294,967,296 | 4-byte max + 1 (4 GB) |
To convert a decimal number to hexadecimal, use the repeated division by 16 method:
255 to Hex1000 to Hex43,981 to HexHexadecimal addition works exactly like decimal addition, except that a carry occurs when the column sum reaches 16 or more (instead of 10 in decimal). Here are the key rules:
1F + 2A7C5 + 3BAFFF + 1This example shows how hex carries cascade through all columns, similar to 999 + 1 = 1000 in decimal.
Hexadecimal subtraction follows the same principle as decimal subtraction, except borrowing adds 16 (instead of 10 in decimal). Here are the key rules:
3A − 1FA3C − 5D71000 − 1This is the inverse of the addition example above — cascading borrows fill every column with F, just as 1000 − 1 = 999 in decimal.
Hex multiplication uses the same long multiplication technique as decimal. The key difference is that you multiply hex digits, convert the products to hex, and carry values in multiples of 16.
A × 3 (Single-digit)1F × 32F × 15 (Multi-digit × Multi-digit)Hex division can be performed using long division in hex, or more practically by converting to decimal, dividing, and converting back. For integer division, the result includes both a quotient and a remainder.
FF ÷ 103E8 ÷ AABCD ÷ 1FThese are the most frequently encountered hex values in software development, networking, and systems programming:
| Hex Value | Decimal | Significance |
|---|---|---|
| 0x00 | 0 | Null byte, string terminator in C |
| 0x0A | 10 | Line feed (LF) — newline character |
| 0x0D | 13 | Carriage return (CR) |
| 0x20 | 32 | Space character (ASCII) |
| 0x41 | 65 | Letter 'A' in ASCII |
| 0x61 | 97 | Letter 'a' in ASCII |
| 0x7F | 127 | Max 7-bit signed integer (DEL character) |
| 0xFF | 255 | Max 1-byte unsigned value (8-bit) |
| 0x100 | 256 | One byte overflow boundary |
| 0x3E8 | 1,000 | One thousand |
| 0xFFF | 4,095 | Max 12-bit unsigned value |
| 0xFFFF | 65,535 | Max 2-byte unsigned value (16-bit) |
| 0xFFFFFF | 16,777,215 | Max 24-bit value (white color #FFFFFF) |
| 0xFFFFFFFF | 4,294,967,295 | Max 4-byte unsigned value (32-bit) |
| 0xDEADBEEF | 3,735,928,559 | Common debug/magic number |
| 0xCAFEBABE | 3,405,691,582 | Java class file magic number |
In web development and design, colors are specified using 6-digit hex codes in the format #RRGGBB. Each pair of hex digits represents one color channel:
00–FF)#FF5733| Hex Code | RGB Decimal | Color Name |
|---|---|---|
| #000000 | rgb(0, 0, 0) | Black |
| #FFFFFF | rgb(255, 255, 255) | White |
| #FF0000 | rgb(255, 0, 0) | Red |
| #00FF00 | rgb(0, 255, 0) | Green (Lime) |
| #0000FF | rgb(0, 0, 255) | Blue |
| #FFFF00 | rgb(255, 255, 0) | Yellow |
| #FF00FF | rgb(255, 0, 255) | Magenta |
| #00FFFF | rgb(0, 255, 255) | Cyan |
| #808080 | rgb(128, 128, 128) | Gray |
| #FFA500 | rgb(255, 165, 0) | Orange |
Shorthand notation uses 3 hex digits where each digit is doubled: #F60 = #FF6600. CSS also supports an 8-digit format #RRGGBBAA where the last pair represents alpha (opacity).
In computing, negative numbers are typically represented using two's complement. The interpretation of a hex value depends on the bit-width of the system:
| Hex | Unsigned (8-bit) | Signed (8-bit) |
|---|---|---|
| 00 | 0 | 0 |
| 01 | 1 | +1 |
| 7F | 127 | +127 (max positive) |
| 80 | 128 | −128 (min negative) |
| FE | 254 | −2 |
| FF | 255 | −1 |
Most programming languages support hex literals with a prefix. Here's how to use hex values across popular languages:
| Language | Hex Literal Syntax | Example |
|---|---|---|
| Python | 0x prefix | x = 0xFF → 255 |
| JavaScript | 0x prefix | let x = 0xFF; → 255 |
| C / C++ | 0x prefix | int x = 0xFF; → 255 |
| Java | 0x prefix | int x = 0xFF; → 255 |
| C# | 0x prefix | int x = 0xFF; → 255 |
| Rust | 0x prefix | let x = 0xFF; → 255 |
| Go | 0x prefix | x := 0xFF → 255 |
| Swift | 0x prefix | let x = 0xFF → 255 |
| PHP | 0x prefix | $x = 0xFF; → 255 |
| Assembly | 0x or h suffix | MOV AX, 0FFh |
| CSS / HTML | # prefix | #FF5733 |
Hexadecimal is ubiquitous in computing and technology. Here are its most important applications:
When debugging software or analyzing crash dumps, memory addresses are displayed in hex. A 64-bit address like 0x7FFE3C2A1000 is far more readable than its 48-digit binary equivalent.
Web colors use the #RRGGBB format. For example, #1E90FF is "Dodger Blue." Each pair encodes a color channel from 0 (none) to FF (full intensity).
Every network interface has a unique 48-bit MAC address written in hex: 00:1A:2B:3C:4D:5E. Each pair is one byte.
IPv6 addresses use eight groups of four hex digits separated by colons: 2001:0db8:85a3:0000:0000:8a2e:0370:7334.
Unicode code points are written in hex: U+0041 = 'A', U+1F600 = '😀'. UTF-8 byte sequences are also expressed in hex.
Files start with "magic bytes" to identify their format. For example, PDF files begin with 25 50 44 46 (%PDF in ASCII). Hex editors display and edit raw file bytes.
CPU opcodes, register values, and instruction encodings are written in hex. The x86 instruction B8 FF 00 00 00 means "move 255 into EAX."
Hash functions like MD5, SHA-1, and SHA-256 output digests as hex strings. For example, the SHA-256 of "hello" starts with 2cf24dba5fb0....
Each cell shows the product of the row header × column header in hexadecimal. This table is useful for manual hex multiplication and verification. For example, to find C × B, look at row C, column B → 84 (which is 132₁₀).
A hex calculator is a tool that performs arithmetic operations (addition, subtraction, multiplication, division) directly on hexadecimal numbers. It also converts between hexadecimal and decimal number systems, showing step-by-step solutions.
Add corresponding digits from right to left, converting A–F to 10–15. If a column sum is 16 or more, subtract 16 and carry 1 to the next column. For example, B + 7 = 18, so write 2 (18 − 16) and carry 1.
Subtract digits right to left. If the top digit is smaller than the bottom digit, borrow 16 from the next column and add it to the current digit, then subtract. For example, to compute 3 − A: borrow to get 19 − 10 = 9.
Decimal is base-10 (digits 0–9) and is the standard human counting system. Hexadecimal is base-16 (digits 0–F) and is used in computing because it maps perfectly to binary: each hex digit = 4 bits. The number 255 in decimal is FF in hex and 11111111 in binary.
Computers operate in binary (base-2), but binary strings are very long and error-prone for humans. Hex provides a 4:1 compression ratio — one hex digit replaces four binary digits — while maintaining perfect alignment with byte (8-bit) and word (16/32/64-bit) boundaries. This makes hex ideal for representing memory, colors, and machine instructions.
The 0x prefix is a convention in most programming languages (C, C++, Java, JavaScript, Python, etc.) to indicate that the following number is hexadecimal. For example, 0xFF means hex FF (decimal 255). Without the prefix, FF might be interpreted as a variable name.
A single byte (8 bits) has a maximum value of FF in hex, which equals 255 in decimal. For signed 8-bit integers using two's complement, the range is 80 (−128) to 7F (+127).
Hex color codes use the format #RRGGBB, where RR, GG, and BB are hex values (00–FF) for Red, Green, and Blue channels. #000000 is black, #FFFFFF is white, and #FF0000 is pure red. Each channel has 256 possible values (0–255), giving 16.7 million possible colors.
Hexadecimal itself does not define negative numbers, but in computing, negative values are represented using two's complement. For example, in an 8-bit signed system, FF represents −1, and 80 represents −128. The interpretation depends on whether the system treats the value as signed or unsigned.
For large hex numbers, use positional notation: multiply each digit by its power of 16 and sum the results. For very large values, use our calculator above or programming functions like Python's int('DEADBEEF', 16) which returns 3,735,928,559.
Explore our other free number conversion tools: