Hex Calculator

Add, subtract, multiply and divide hexadecimal numbers, use bitwise AND, OR and XOR, and convert between hex and decimal, with every step shown.

Hex calculator
Calculate
Result

    Working

    Works with whole numbers of any length using exact arithmetic. Negative numbers can be entered with a minus sign. Division gives the whole-number quotient and the remainder. AND, OR and XOR compare the bits of non-negative numbers.

    On this page

    A hex calculator adds, subtracts, multiplies and divides hexadecimal numbers, performs bitwise AND, OR and XOR, and converts between hexadecimal and decimal, showing every step. Each result is also shown in binary and octal, and the calculator uses exact arithmetic, so even very long hex numbers are handled without rounding.

    For example, 1A3F + FF = 1B3E in hex, which is 6,719 + 255 = 6,974 in decimal. FF in hex is 255 in decimal, 2D is 45, and the decimal number 65,535 is FFFF in hexadecimal.

    How to use the hex calculator

    1. Choose hex arithmetic, hex to decimal, or decimal to hex.
    2. Enter hex numbers using the digits 0–9 and the letters A–F, in upper or lower case. A 0x or # prefix is accepted and ignored.
    3. For arithmetic, choose an operation: add, subtract, multiply, divide, AND, OR or XOR.
    4. Press Calculate to see the result in hex, decimal, binary and octal, with the working.

    What is hexadecimal?

    Hexadecimal, or hex, is a base-16 number system. It uses sixteen digits: 0 to 9 for the values zero to nine, and A, B, C, D, E and F for ten to fifteen. Each position is worth 16 times the one to its right: 1, 16, 256, 4,096 and so on. Hex is popular in computing because one hex digit represents exactly four binary digits (bits), so a byte of 8 bits is always two hex digits, from 00 to FF.

    HexDecimalBinary
    000000
    991001
    A101010
    B111011
    C121100
    D131101
    E141110
    F151111
    10161 0000
    FF2551111 1111

    Converting hex to decimal

    Multiply each digit by its place value, a power of 16, and add the results. For 2D: 2 × 16 + 13 × 1 = 32 + 13 = 45. For FFFFFF, the largest six-digit hex number: 15 × 16⁵ + 15 × 16⁴ + … + 15 × 16⁰ = 16,777,215. That’s one less than the 16,777,216 colours available in 24-bit colour, because counting starts at 000000 for black.

    Converting decimal to hex

    Divide by 16 repeatedly and write down each remainder, using A to F for remainders of 10 to 15. Read the remainders from last to first. For 255: 255 ÷ 16 = 15 remainder 15 (F), and 15 ÷ 16 = 0 remainder 15 (F), giving FF. For 45: 45 ÷ 16 = 2 remainder 13 (D), and 2 ÷ 16 = 0 remainder 2, giving 2D.

    Converting between hex and binary

    Because each hex digit equals four bits, converting is quick: replace each hex digit with its four-bit pattern. 2D becomes 0010 1101. To go the other way, split the binary number into groups of four from the right and convert each group: 1111 0000 becomes F0. This is why programmers prefer hex for reading binary data: it’s four times shorter and still maps directly to the bits.

    Hex arithmetic

    Addition

    Add column by column from the right, as in decimal, but carry when a column reaches 16 instead of 10. For F + 1, 15 + 1 = 16, so write 0 and carry 1: the result is 10. 1A3F + FF = 1B3E.

    Subtraction

    Subtract column by column, borrowing 16 from the next column when needed. FF − 1A = E5, which is 255 − 26 = 229.

    Multiplication and division

    These work like decimal long multiplication and division, but are easiest to check by converting to decimal. 1F × A = 136 (31 × 10 = 310), and FF ÷ 10 = F remainder F (255 ÷ 16 = 15 remainder 15).

    Bitwise operations in hex

    • AND keeps bits that are 1 in both numbers. It’s used to mask values, for example FF AND 0F = 0F keeps only the low four bits.
    • OR sets bits that are 1 in either number, for example to switch on flags.
    • XOR sets bits that differ: F0 XOR 0F = FF. It’s used for toggling bits, checksums and simple encryption.

    Worked example: decoding a colour

    The web colour #FF5733 is a warm orange-red. Split it into three pairs: FF, 57 and 33. Converting each to decimal gives red = 255, green = 5 × 16 + 7 = 87 and blue = 3 × 16 + 3 = 51, so the colour is rgb(255, 87, 51). To lighten it, increase the green and blue values; to make pure red, use #FF0000. Three-digit shorthand codes double each digit, so #F53 means #FF5533 and #FFF means white, #FFFFFF.

    Negative numbers in hex

    This calculator shows negative results with a minus sign, such as −1A. Inside computers, negative numbers are usually stored as two’s complement, which looks very different in hex. In a 32-bit integer, −1 is stored as FFFFFFFF, and −16 as FFFFFFF0. If you see a large hex value starting with F in a debugger, it may actually be a small negative number. To find the value, subtract it from 100000000 (2³²) and add a minus sign: 100000000 − FFFFFFF0 = 10, so FFFFFFF0 is −16.

    Place values in hex

    PositionPower of 16Value
    1st (right)16⁰1
    2nd16¹16
    3rd16²256
    4th16³4,096
    5th16⁴65,536
    6th16⁵1,048,576

    Four hex digits cover 0 to 65,535 (FFFF), the range of a 16-bit number, and eight cover 0 to 4,294,967,295 (FFFFFFFF), the range of a 32-bit number.

    Hex, decimal and binary side by side

    All three systems describe the same numbers; they just group them differently. Decimal is natural for people because we have ten fingers. Binary is natural for computers because circuits are either off or on. Hex sits in between: it’s compact enough for people to read and write, while mapping perfectly onto the binary that computers use. A 32-bit value such as 3,735,928,559 in decimal is a long string of 32 ones and zeros in binary, but only eight characters in hex: DEADBEEF, a value programmers sometimes use as a recognisable marker in memory.

    Common mistakes

    • Reading hex 10 as ten instead of sixteen.
    • Using the letter O instead of the digit 0, or I instead of 1; only 0–9 and A–F are valid.
    • Forgetting to carry at 16 rather than 10 when adding by hand.
    • Mixing up the order of the colour pairs in web colours: it’s always red, then green, then blue.

    Tips for working with hex

    • Memorise A = 10 to F = 15; everything else follows.
    • Remember that hex 10 is decimal 16, not ten, and hex 100 is 256.
    • Pad values to an even number of digits when they represent bytes: 0F rather than F.
    • Check answers by converting to decimal, doing the sum there and converting back.

    Where hexadecimal is used

    • Web colours: HTML and CSS colours such as #FF5733 are three hex bytes for red, green and blue. FF means full intensity (255) and 00 means none.
    • Memory addresses: debuggers and system tools show addresses like 0x7FFE in hex.
    • Error codes: operating systems often report errors as hex codes.
    • MAC addresses: network hardware addresses are written as six pairs of hex digits.
    • Unicode characters: code points such as U+00E9 for é are written in hex.
    • File formats and data: hex editors show the raw bytes of a file.

    Related calculations

    Two other tools work well alongside this one: the binary calculator, to do binary arithmetic and convert binary to decimal, and the scientific notation calculator, to convert numbers to and from scientific notation.

    Frequently asked questions

    Multiply each digit by its place value (1, 16, 256, …) and add the results, using A = 10 to F = 15. 2D = 2 × 16 + 13 = 45.

    Divide by 16 repeatedly, write down the remainders (10–15 as A–F) and read them from last to first. 255 becomes FF.

    255. It's the largest value that fits in one byte, because two hex digits cover 256 values from 00 to FF.

    Only A, B, C, D, E and F, standing for 10 to 15.

    Each hex digit represents exactly four bits, so hex is a compact, readable way to write binary data such as bytes, colours and memory addresses.

    A code like #FF5733 has three pairs of hex digits for red, green and blue, each from 00 (none) to FF (full, 255).

    It's a common prefix in programming that marks a number as hexadecimal, as in 0xFF. The calculator accepts it.

    Add column by column from the right and carry 1 whenever a column reaches 16. F + 1 = 10 in hex.

    No. ff, FF and fF all mean 255. The calculator shows results in capital letters.

    Red 255, green 87 and blue 51, written rgb(255, 87, 51).

    16. In hexadecimal, 10 means one sixteen and zero ones, just as decimal 10 means one ten and zero ones.

    In 32-bit two's complement, the bit pattern FFFFFFFF represents −1. Unsigned, the same pattern is 4,294,967,295.

    Replace each hex digit with its four-bit binary pattern. 2D becomes 0010 1101.

    It's shorthand for #FFFFFF, which is white. Each digit is doubled, so #F53 means #FF5533.

    256, from 00 to FF, which is exactly one byte.