Math · Live
Hex Calculator,
four bases at once.
Perform hexadecimal arithmetic (+ − × ÷) and bitwise operations (AND, OR, XOR, NOT, shifts) with results displayed simultaneously in hex, decimal, binary, and octal. Includes a visual hex keypad, a standalone base converter, and an 8/16/32-bit mode.
Bit width
Affects NOT, overflow detection, and zero-padding
Arithmetic
Hex keypad
Number converter
Max 8-bit value — 255 decimal · 0xFF hex
Result
HEX
0x0E
DEC
14
BIN
0000 1110
OCT
16
⚠ Overflow: result exceeds 8 bits, truncated.
Working
0xFF (255 dec) + 0x0F (15 dec) ────────────────── = 0x0E (14 dec) ⚠ Overflow: result truncated to 8 bits
Converter result
Nibble reference (0 – F)
| HEX | DEC | BIN | OCT |
|---|---|---|---|
| 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 |
Complete guide
What is hexadecimal?
Hexadecimal (base 16) is a numeral system that uses sixteen distinct symbols: the digits 0–9 and the letters A–F, where A represents 10, B represents 11, C represents 12, D represents 13, E represents 14, and F represents 15. The prefix "0x" is the standard notation used in programming to indicate a hexadecimal literal (e.g., 0xFF = 255 in decimal).
Hex is ubiquitous in computing because it maps cleanly onto binary: each hex digit corresponds to exactly 4 binary bits (a "nibble"). This makes it far more compact than writing binary while still preserving exact bit-level structure — a 32-bit value needs 8 hex digits versus 32 binary digits.
The four number bases in computing
| Base | Name | Digits | Prefix | Example (255) |
|---|---|---|---|---|
| 2 | Binary | 0–1 | 0b | 11111111 |
| 8 | Octal | 0–7 | 0o | 377 |
| 10 | Decimal | 0–9 | — | 255 |
| 16 | Hexadecimal | 0–9, A–F | 0x | FF |
Hex to decimal conversion
To convert from hexadecimal to decimal, multiply each digit by its positional power of 16 and sum the results. Hex digits are read right to left (least-significant to most-significant), with the rightmost digit at position 0:
Position: 3 2 1 0
Digit: 1 A 3 F
Value: 1 10 3 15
= 1×16³ + 10×16² + 3×16¹ + 15×16⁰
= 4096 + 2560 + 48 + 15
= 6,719
Decimal to hex conversion
To convert from decimal to hexadecimal, repeatedly divide the number by 16, recording the remainder at each step. Read the remainders bottom-to-top:
6719 ÷ 16 = 419 remainder 15 (F)
419 ÷ 16 = 26 remainder 3 (3)
26 ÷ 16 = 1 remainder 10 (A)
1 ÷ 16 = 0 remainder 1 (1)
Reading remainders upward: 0x1A3F ✓
Hex and binary: the natural connection
The power of hexadecimal in computing comes from its direct relationship with binary. Because 16 = 2⁴, each hex digit maps exactly to a 4-bit group. Converting between hex and binary requires only a simple digit-by-digit substitution — no arithmetic needed:
A = 1010 3 = 0011
→ 1010 0011 = 0b10100011
0b11001010 → hex:
Group by 4: 1100 1010
C A
→ 0xCA
Bitwise operations explained
Bitwise operations act directly on individual bits of integer values. They are fundamental operations in low-level programming, hardware design, cryptography, and graphics:
- AND (&): Output bit is 1 only when both input bits are 1. Used to mask (isolate) specific bits. Example:
0xFF & 0x0F = 0x0F— extracts the lower nibble. - OR (|): Output bit is 1 when at least one input bit is 1. Used to set specific bits. Example:
0xF0 | 0x0F = 0xFF— sets all bits. - XOR (^): Output bit is 1 when input bits differ. Used to toggle bits, compare values, and in many encryption algorithms. Example:
0xFF ^ 0x0F = 0xF0. - NOT (~): Flips every bit. In an 8-bit context,
~0x0F = 0xF0. The result depends on the bit width — NOT of 0x0F in 16-bit gives 0xFFF0. - Left shift (<<): Shifts all bits left by N positions, filling with zeros on the right. Equivalent to multiplying by 2ᴺ (subject to overflow). Example:
0x01 << 4 = 0x10. - Right shift (>>): Shifts all bits right by N positions. Equivalent to integer division by 2ᴺ. Example:
0x80 >> 3 = 0x10.
Common uses of hexadecimal
- Memory addresses. Pointers and memory locations in system programming are almost always displayed as hex because they align with the system's word size (e.g., 64-bit addresses as 16 hex digits).
- Colour codes. Web colours use the format
#RRGGBBwhere each pair of hex digits (00–FF) represents a colour channel intensity.#FF5733is an orange-red with red=255, green=87, blue=51. - Byte representation. File headers, network packets, and binary data are displayed as hex dumps — two hex digits per byte, making the data human-readable without losing byte-level precision.
- Bitmasks and flags. Permission flags, hardware registers, and protocol fields are often defined as hex constants that can be combined with bitwise OR and tested with bitwise AND.
- Checksums and hashes. MD5 produces a 128-bit (32 hex digit) hash; SHA-256 produces 256 bits (64 hex digits). Hex is the universal display format for cryptographic output.
Hex arithmetic examples
| Expression | Hex result | Decimal | Binary |
|---|---|---|---|
| 0xFF + 0x01 | 0x100 | 256 | 1 0000 0000 |
| 0xA0 − 0x0F | 0x91 | 145 | 1001 0001 |
| 0x0F × 0x0F | 0xE1 | 225 | 1110 0001 |
| 0xFF ÷ 0x10 | 0x0F | 15 | 0000 1111 |
| 0xFF AND 0x0F | 0x0F | 15 | 0000 1111 |
| 0xF0 OR 0x0F | 0xFF | 255 | 1111 1111 |
| 0xFF XOR 0xAA | 0x55 | 85 | 0101 0101 |
| NOT 0x0F (8-bit) | 0xF0 | 240 | 1111 0000 |
| 0x01 << 4 | 0x10 | 16 | 0001 0000 |
| 0x80 >> 3 | 0x10 | 16 | 0001 0000 |
Understanding overflow and bit width
Integers in computers have a fixed bit width — 8, 16, 32, or 64 bits. When the result of an arithmetic operation exceeds the maximum value for that width, the excess bits are discarded. This is called overflow (or wrap-around for unsigned integers).
0xFF + 0x01 = 0x100 (256 in decimal)
→ 256 exceeds 8-bit, result wraps to 0x00 (overflow)
0x00 − 0x01 = −1 in signed, or 0xFF in unsigned 8-bit
→ underflow wraps to 0xFF = 255
The bit-width selector in this calculator controls how overflow, underflow, and NOT behave. Switch between 8, 16, and 32 bits to see how the same operation produces different results at different precisions.
Hexadecimal colour codes
Web and graphic design use hex triplets to encode RGB colours. Each colour channel (Red, Green, Blue) ranges from 0x00 (0) to 0xFF (255), represented as two hex digits:
#FF0000 = pure red (R=255, G=0, B=0)
#00FF00 = pure green (R=0, G=255, B=0)
#0000FF = pure blue (R=0, G=0, B=255)
#FFFFFF = white (R=255, G=255, B=255)
#000000 = black (R=0, G=0, B=0)
#FF5733 = orange-red (R=255, G=87, B=51)