Hex Calculator
Convert between hexadecimal, decimal, binary, and octal. Perform hex arithmetic and calculations for programming and web design.
About the Hex Calculator
A hexadecimal (hex) calculator performs arithmetic — addition, subtraction, multiplication, and division — in base-16, and converts between hexadecimal, decimal, binary, and octal number representations. Hexadecimal is ubiquitous in computing and digital electronics: HTML and CSS color codes (#FF5733), memory addresses in debugging output, machine code opcodes, network MAC addresses, IPv6 addresses, cryptographic hashes (SHA-256, MD5), and binary file headers are all conventionally expressed in hexadecimal. Each hex digit represents exactly four binary bits (one nibble), making hex a maximally compact and human-readable way to work with binary data — a 32-bit memory address requires only 8 hex digits versus 32 binary digits. Our hex calculator handles arithmetic with proper carry and borrow logic, supports all four basic operations, computes bitwise AND, OR, XOR, and NOT operations, and instantly converts any value between all four number bases.
Formula
Hex to decimal: sum(digit x 16^position) | Decimal to hex: repeated division by 16 | Each hex digit = 4 binary bits
How It Works
Hexadecimal digits: 0-9 then A(10), B(11), C(12), D(13), E(14), F(15). Place values: 16^0=1, 16^1=16, 16^2=256, 16^3=4,096, 16^4=65,536. Hex to decimal: sum each digit multiplied by its place value. 0x2A3F = 2x4096 + 10x256 + 3x16 + 15x1 = 8,192 + 2,560 + 48 + 15 = 10,815. Decimal to hex: repeatedly divide by 16, read remainders from bottom to top. 255: 255/16=15r15, so 255 = 0xFF. Hex addition: A + 7 = 10+7 = 17 = 11 in hex (write 1, carry 1). Hex to binary: replace each hex digit with its 4-bit binary equivalent. F=1111, A=1010, 5=0101. 0xFA5 = 1111 1010 0101 in binary.
Tips & Best Practices
- ✓HTML/CSS colors: #RRGGBB where each pair is a 2-digit hex byte (00=0, FF=255). #FF0000=red, #00FF00=green, #0000FF=blue, #FFFFFF=white, #000000=black, #808080=50% gray.
- ✓Memory addresses in 64-bit systems use 16 hex digits: 0x00007FFE5ABF3C20 is a typical stack address in a 64-bit Windows process.
- ✓Prefix conventions: 0x prefix in C, Java, JavaScript; $ in assembly language; # in some assembly dialects; H suffix in some older notations.
- ✓One hex digit = 4 bits = one nibble. Two hex digits = 8 bits = one byte (range 0x00 to 0xFF = 0 to 255).
- ✓XOR in security: the XOR operation (exclusive OR) is used in stream ciphers and one-time pad encryption. XOR with the same key twice restores the original value: A XOR K XOR K = A.
- ✓RGB to hex for web development: RGB(255, 87, 51) converts to hex by converting each value individually: 255=FF, 87=57, 51=33. Result: #FF5733.
- ✓Bitmasking: AND operation with a mask selects specific bits. Example: to extract the lower nibble of a byte: 0xAB AND 0x0F = 0x0B (keeps only the rightmost 4 bits).
- ✓Error codes: Windows BSOD stop codes, HTTP error codes, and Unix errno values are often expressed in hex — 0xC0000005 (access violation), 0x404 (not found), 0x16 (invalid argument).
Who Uses This Calculator
Web developers choosing HTML color codes. Programmers debugging memory addresses, register contents, and binary data. System administrators parsing log files with hex error codes. Electronics engineers reading microcontroller register maps and datasheets. Computer science students learning digital number systems and boolean algebra. Cybersecurity analysts examining binary files and network packets in hex editors.
Optimised for: USA · Canada · UK · Australia · Calculations run in your browser · No data stored
Frequently Asked Questions
How do you convert hex to decimal?
Hex FF = 15×16 + 15×1 = 255. Each hex digit represents 4 binary bits, so FF in binary is 11111111.