FLXCode Hex Calculator

FLXCode apps

Appearance

Hex Calculator

Do arithmetic in hexadecimal. Type the digits 0 to 9 and A to F, press an operation, and read the answer in hex, decimal, octal and binary.

Type with the keyboard or the keys below, or paste a number. Click a row to type in that base.

Bits (click one to flip it)

Try an example

History (this visit only)

    Nothing yet. Results appear here, newest first.

    Keyboard shortcuts
    0–9, A–Ftype digits (digits outside the input base are refused)
    + − * / %add, subtract, multiply, divide, modulo
    & | ^ ~AND, OR, XOR, NOT
    q wNAND, NOR
    < > sshift left, shift right (logical), shift right (arithmetic)
    r Shift+Rrotate left, rotate right
    nchange sign
    Enter or =equals (ENTER in RPN mode)
    Backspacedelete the last digit
    Escclear the number; press again to clear everything
    x k DeleteRPN: swap X and Y, roll the stack down, drop X

    No ads. No account. Nothing you type or record is uploaded. We count page events with a daily code. Check it.

    Problem or idea? Email us

    Quick start

    1. HEX is already the input row. Type the first number with the keypad or the keyboard.
    2. Press +, −, × or ÷, then type the second number and press =.
    3. Read the answer in the HEX row, or in DEC if you want the decimal value.
    4. If a flag line appears, the answer was cut to the word size. Choose a larger word to keep every bit.

    Worked examples

    SumWordHex resultDecimal resultFlagWhy
    FF + 18-bit unsigned000carryOne byte is full. The sum needs a ninth bit, so the byte wraps to 00 with carry.
    7FFF + 116-bit signed8000-32768overflowThe largest signed 16-bit number plus one flips the sign bit: overflow.
    7FFFFFFF + 132-bit signed80000000-2147483648overflowThe same thing at 32 bits.
    DEADBEEF − BEEF32-bit unsignedDEAD00003735879680noneClearing the low half of a famous marker.
    1000 − 116-bit unsigned0FFF4095noneBorrowing runs through every zero digit.
    0 − 116-bit unsignedFFFF65535carryBelow zero wraps to the top, with borrow.
    FF × FF16-bit unsignedFE0165025none255 × 255 = 65025 fits in 16 bits.
    FF × FF8-bit unsigned011carryThe same product in 8 bits keeps only the low byte, with carry.
    100 ÷ 3032-bit unsigned000000055, remainder 16none256 ÷ 48 is 5 remainder 16, written here in decimal.

    The six extra digits

    A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. Everything else is as in decimal, except that a column holds up to 15 before it carries.

    Adding by hand

    2B7 + 19C, working from the right. A column that reaches 16 or more writes its remainder and carries 1.

    ColumnTopBottomCarry inTotal (decimal)WriteCarry out
    17C01931
    2B912151
    3211440

    The answer is 453.

    Subtracting by hand

    5A2 - 1F7. When the top digit is too small, borrow 1 from the next column, which adds 16 here.

    ColumnTopBorrowed inTop afterBottomWriteBorrow out
    120187B1
    2A125FA1
    3514130

    The answer is 3AB.

    When the answer wraps

    A register holds a fixed number of bits, so every result is cut to that width. Hex makes the cut easy to see: at 16 bits, the result keeps its last four hex digits. FFFF + 1 is 10000 on paper and 0000 in the register, with the carry set. The flag line under the screen says which of the two flags applies. Carry is for unsigned numbers, overflow is for signed ones.

    Where hex arithmetic turns up

    • Memory addresses: a base address plus an offset, as in 0x4000 + 0x1C.
    • Colour values: adding to a channel such as 0x80 + 0x40 without running past 0xFF.
    • Masks and sizes: 0x1000 - 1 is the mask 0xFFF for a 4 KiB page.
    • Hex dumps and checksums: adding bytes and keeping only the low byte.

    To convert a value without doing arithmetic use hex to decimal or hex to binary. For shifts, rotates and bit masks open the programmer calculator.

    Numbers this uses

    • Hex digits 0 to 9 and A to F. Case does not matter when pasting.
    • Word sizes 8, 16, 32 and 64 bits, exact integers (BigInt).
    • Division is integer division that rounds toward zero. The remainder is shown beside the quotient.

    Nothing you type is uploaded. We count events without cookies (details).

    FAQ

    How do I add hex numbers?

    Add column by column from the right, like decimal, but a column carries when it reaches 16 instead of 10. 7 + C is 19 in decimal, which is 13 in hex: write 3 and carry 1. The worked column table above does 2B7 + 19C step by step.

    How do I subtract in hex?

    Subtract column by column. When the top digit is smaller than the bottom digit, borrow 1 from the next column. That adds 16 to the column you are working on, not 10. The column table above shows 5A2 - 1F7 with the borrows.

    What does it mean when the result wraps?

    The calculator works in a fixed width, like a processor register. FF + 1 needs nine bits, but an 8-bit register holds eight, so the extra bit is dropped and the result is 00. The carry flag tells you it happened. Choose 32 or 64 bits if you want room for bigger sums.

    Which word size should I pick?

    Use the size of the value you are working with: 8 bits for a byte or a register on a small chip, 16 for a short, 32 for an int on most platforms and an IPv4 address, 64 for a pointer on a modern PC. This page starts at 32.

    Can the calculator handle negative hex numbers?

    Yes, in signed mode. FFFF at 16 bits is -1 there, and FFFE is -2. You can also type -1 in decimal and read FFFF in the HEX row. Hex numbers do not have a minus sign inside the word. They are bit patterns.

    Do I type 0x in front?

    No need. With the HEX row selected the keys 0 to 9 and A to F are all you need. If you paste a number that starts with 0x or $ it is read as hex anyway. Underscores and spaces in a pasted number are ignored.

    Why does the examples table show decimal next to hex?

    So you can check each sum with ordinary numbers. In the calculator the remainder of a division is shown in the input base, so it is in hex while the HEX row is selected. Click DEC to read it in decimal.

    Is anything I type saved or sent?

    No. The calculator runs in your browser. What you type is not put in the address bar, not stored and not counted. Your last word size and base are remembered on this device, and nothing else.

    More from FLXCode

    Share Hex Calculator