Skip to main content
ilovecalcs logoilovecalcs.

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.

Full guideReal-time

Bit width

Affects NOT, overflow detection, and zero-padding

Arithmetic

0x
Arith
Bitwise
Shift
0x

Hex keypad

Typing to:

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

HEX0xFF
DEC255
BIN1111 1111
OCT377

Nibble reference (0 – F)

HEXDECBINOCT
0000000
1100011
2200102
3300113
4401004
5501015
6601106
7701117
88100010
99100111
A10101012
B11101113
C12110014
D13110115
E14111016
F15111117

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

BaseNameDigitsPrefixExample (255)
2Binary0–10b11111111
8Octal0–70o377
10Decimal0–9255
16Hexadecimal0–9, A–F0xFF

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:

Convert 0x1A3F to decimal:

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:

Convert 6719 to hex:

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:

0xA3 → binary:
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 #RRGGBB where each pair of hex digits (00–FF) represents a colour channel intensity. #FF5733 is 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

ExpressionHex resultDecimalBinary
0xFF + 0x010x1002561 0000 0000
0xA0 − 0x0F0x911451001 0001
0x0F × 0x0F0xE12251110 0001
0xFF ÷ 0x100x0F150000 1111
0xFF AND 0x0F0x0F150000 1111
0xF0 OR 0x0F0xFF2551111 1111
0xFF XOR 0xAA0x55850101 0101
NOT 0x0F (8-bit)0xF02401111 0000
0x01 << 40x10160001 0000
0x80 >> 30x10160001 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).

8-bit unsigned max = 0xFF = 255

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:

#RRGGBB format:
#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)