FLXCode Programmer Calculator

FLXCode apps

Appearance

Programmer Calculator

Type a number and see it in hex, decimal, octal and binary at once. Pick a word size from 8 to 64 bits, do the arithmetic or the bit work, and watch for the carry and overflow flags.

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. Choose a word size and whether the bits are signed or unsigned.
    2. Click a row (HEX, DEC, OCT or BIN) to say which base you will type in. Keys that are not digits in that base switch off.
    3. Type digits, press an operation, type the second number and press =. Or turn on RPN.
    4. Flip single bits in the bit grid, or copy any row with its prefix.

    Worked examples

    SumWordResult in hexResult in decimalFlagWhat happens
    0xFF + 0x018-bit unsigned000carryThe byte is full, so it wraps to zero and the carry flag is set.
    0x7FFF + 116-bit signed8000-32768overflowThe largest signed 16-bit value plus one: overflow, and the number turns negative.
    0x00 − 0x018-bit unsignedFF255carryBorrow: zero minus one wraps to the top of the range.
    -128 SAR 18-bit signedC0-64noneArithmetic shift keeps the sign bit, so a negative stays negative.
    0x80 SHR 18-bit unsigned4064noneLogical shift brings in a zero: 0x80 becomes 0x40.
    0x81 ROL 18-bit unsigned033carryThe top bit comes round to bit 0, and nothing is lost.
    NOT 0x0F8-bit unsignedF0240noneEvery bit flips. At 8 bits NOT x is 0xFF xor x.
    17 ÷ 532-bit unsigned000000033, remainder 2noneInteger division: the quotient, and the remainder next to it.
    -17 ÷ 532-bit signedFFFFFFFD-3, remainder -2noneDivision rounds toward zero, so the remainder keeps the sign of -17.
    -7 MOD 38-bit signedFF-1noneMOD takes the sign of the first number, as in C.

    Word sizes and ranges

    BitsSigned minimumSigned maximumUnsigned maximumIn hex
    8 (byte)-1281272550xFF
    16 (word)-3276832767655350xFFFF
    32 (long)-2147483648214748364742949672950xFFFFFFFF
    64 (quad)-92233720368547758089223372036854775807184467440737095516150xFFFFFFFFFFFFFFFF

    The names byte, word, long and quad follow the 68000 and Amiga convention. Other families use different names: on x86 a word is 16 bits, and a double word is 32.

    Two's complement: why 0xFF is -1

    A computer stores a negative number by counting backwards from zero in a fixed number of bits. One less than 0 wraps to all ones. So -1 is all ones in every word size, -2 is all ones except the last bit, and so on. The top bit is the sign: in a signed reading it is worth minus 2 to the power of (bits - 1).

    Bits-1 in hexSigned readingUnsigned reading
    8FF-1255
    16FFFF-165535
    32FFFF FFFF-14294967295
    64FFFF FFFF FFFF FFFF-118446744073709551615

    To negate a number by hand, flip all bits and add one. The +/− key does this, and NOT alone does the first half. The most negative value has no positive partner: -128 negated at 8 bits is -128 again, and the calculator flags it as an overflow.

    Carry and overflow

    Every addition, subtraction and multiplication is done exactly and then cut to the word size. The calculator compares the exact answer with what fits. In unsigned mode it reports a carry when the exact answer is outside 0 to the maximum. For a subtraction that is a borrow. In signed mode it reports an overflow when the exact answer is outside the signed range. Shifts and rotates report the last bit that fell out as carry, in either mode.

    Shifts and rotates

    • SHL moves bits left and fills with zeros. One step multiplies by 2 until bits fall off the top.
    • SHR moves bits right and fills with zeros. One step divides an unsigned number by 2 and drops the remainder.
    • SAR moves bits right and copies the sign bit. For negative numbers it rounds toward minus infinity: -7 SAR 1 is -4.
    • ROL and ROR move bits round the end, so nothing is lost. The count is taken modulo the word size.

    The second number is the count. A count of the word size or more empties a logical shift, and fills an arithmetic one with the sign.

    RPN mode

    In RPN you enter the numbers first and the operation after. The stack has four levels. X is the number on screen. An operation takes Y and X, puts the answer in X, and moves Z into Y and T into Z. T keeps its value, so a constant left there can be used again.

    You pressTZYX
    Type 30003
    ENTER0033
    Type 40034
    +0007
    Type 50075
    ×00035

    The table is (3 + 4) × 5 = 35 with no brackets. ENTER copies X up into Y and the next digit replaces the copy. Swap exchanges X and Y, drop removes X, and roll moves the whole stack down one place with X going to the top.

    What you can type or paste

    FormMeaning
    0xFF, $FFHex. The dollar sign is the 68000 assembler style.
    0b1010, %1010Binary. In HEX input 0b1010 is read as hex digits, because B is a digit.
    0o17, @17Octal.
    1111_0000, 1111 0000Underscores and spaces are ignored.
    -1A negative number. It needs signed mode. In unsigned mode type the bit pattern in hex instead.

    A number that does not fit the word size is refused with the largest value that does. Pasting a prefixed number switches the input base to match.

    Numbers this uses

    • Word sizes 8, 16, 32 and 64 bits. Values are exact integers (BigInt), with no floating point anywhere.
    • Signed means two's complement. A decimal number typed in signed mode must be in the signed range. A hex, octal or binary number may use any bit pattern of the word.
    • Division is integer division that rounds toward zero. The remainder is shown beside it. MOD has the sign of the first number.
    • The history keeps the last 12 calculations for this visit only and is not stored.

    For plain conversions without arithmetic, use the number base converter. Pages for the common cases: hex calculator, binary calculator and bitwise calculator.

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

    FAQ

    What is a programmer calculator?

    A calculator that works on whole numbers of a fixed width, the way a CPU register does. It shows one value in hex, decimal, octal and binary at the same time, and it has the operations a programmer needs: AND, OR, XOR, NOT, shifts and rotates, plus the flags that tell you when a result did not fit.

    Why does 0xFF + 1 give 0?

    At 8 bits the largest unsigned value is 255. Adding 1 gives 256, which needs nine bits, so the top bit is dropped and 0 is left. The dropped bit is the carry. Switch to 16 bits and the same sum gives 0x100.

    Why is 0xFF equal to -1 in 8-bit signed mode?

    In two's complement the top bit counts as -128 instead of +128. 0xFF is 1111 1111, which is -128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = -1. The bits are the same in both modes. Only the reading changes, which is why the calculator keeps one bit pattern and shows both.

    What is the difference between carry and overflow?

    Carry says the result did not fit when the numbers are read as unsigned. Overflow says it did not fit when they are read as signed. 0xFF + 1 at 8 bits is a carry but not an overflow (-1 + 1 = 0 is right). 0x7F + 1 is an overflow but not a carry (127 + 1 does not fit, though 128 does fit an unsigned byte). The tool shows the one that matches your signed or unsigned setting.

    What is the difference between SHR and SAR?

    SHR is the logical shift: zeros come in from the left. SAR is the arithmetic shift: the sign bit is copied in, so a negative number stays negative. For a positive number both give the same answer. For -128 at 8 bits, SAR 1 gives -64 and SHR 1 gives 64.

    What sign does MOD give?

    It takes the sign of the first number, which is how C, Java and the 68000 divide: -7 MOD 3 is -1, and 7 MOD -3 is 1. Division rounds toward zero to match. In unsigned mode all values are positive, so MOD is never negative.

    How does the RPN mode work?

    You enter numbers first and the operation after. Type 3, press ENTER, type 4, press +. The result 7 appears in X. Four registers X, Y, Z and T hold the stack. An operation uses X and Y and moves Z and T down. The key row also has swap, drop and roll.

    Are my numbers saved or sent anywhere?

    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, signed setting, base and mode are remembered on this device. A share link carries those settings, and the value on screen only if you tick the box for it.

    More from FLXCode

    Share Programmer Calculator