Binary Two's Complement Calculator
Negate an 8-bit signed binary pattern with NEG. The starting 00000101 is +5 and becomes 11111011, or -5. Choose another fixed width or enter your own bits. NOT gives the one's complement instead; the signed minimum cannot be negated within its width and raises an overflow flag.
NEG 0 0 0 0 0 1 0 1 = 5
------------------------
1 1 1 1 1 0 1 1 = -5
decimal -5 hex 0xFB octal 0373
overflow none bits used 8NEG 00000101 = 11111011, which is -5 in decimal, written in 8 bits. The top bit is 1, so read as two's complement this is a negative value.
Flip the 8 bits and add one, keeping the low 8 bits: this is two's-complement negation. The signed reading determines whether the mathematical negative fits. 8-bit two's complement: these bits hold -128 to 127, and an answer outside that range is flagged as an overflow.
Each box takes binary digits only, and spaces, underscores and an 0b prefix are read rather than refused, so 1010 1010 and 0b10101010 are the same number. With the width on Auto there is no register to fall out of: the numbers are whole integers of any length up to 4096 digits a box, and a subtraction that goes below zero comes back with a minus sign. Pick a width and the same bits become a register: Unsigned reads them as a magnitude, Signed reads the top bit as a sign, and an answer that does not fit is shown wrapped with the overflow flag raised and the exact answer printed beside it. For the two shifts the second box holds the number of places, written in binary like everything else. The column grid is drawn whenever every row fits 24 columns and no minus sign is involved; past that the same rows are printed without the grid. Your entry is kept in this browser so the page opens where you left it.
Binary fractions and IPv4 conversions
Binary fractions and IPv4
These are positional values, with a minus sign for negative values. They are separate from the integer register above and do not interpret a fixed-point encoding. Each input allows 256 characters. Parentheses in output mark a repeating cycle; an ellipsis marks a 128-digit preview. The reduced fraction always remains exact.
- Exact reduced fraction
- Binary exact
- Decimal exact
These conversion fields are kept only while this view is open. They do not write over the integer calculator's remembered inputs.
Common questions
- How is the two's complement calculated?
- Flip all the bits within the chosen width, then add one and retain the low bits. For 00000101 at eight bits, flipping gives 11111010 and adding one gives 11111011. The result is the negative of +5 in signed two's complement.
- Why does the minimum negative number overflow?
- At eight signed bits, the range is -128 through +127. The bit pattern 10000000 is -128, and its mathematical negative +128 cannot fit. NEG therefore retains the wrapped pattern 10000000 while showing the exact +128 answer and an overflow flag. At four bits the corresponding case is 1000, or -8.
- Can I decode an existing signed bit pattern without negating it?
- Select addition, keep Signed and the required width, and put 0 in the second operand. The decimal result is then the original pattern's signed value. Short inputs are zero-padded, so 1111 means +15 at eight bits and -1 at four signed bits.
- What is the difference between NOT and NEG?
- NOT flips bits without adding one, producing the one's complement. NEG produces the two's-complement negative. Both need a fixed width. In Unsigned reading, NEG of a nonzero value wraps a negative arithmetic result and is flagged.
- Does this page change my saved main calculator?
- The stated input, operation, signed reading and eight-bit width override saved values when this page opens. Merely opening it does not save those defaults. Only controls you deliberately change update their saved fields.
Exact integer arithmetic on arbitrary-precision integers, so a long operand is never truncated or turned into a floating-point number. Unsigned is the default and a negative result is labelled as such. Fixed-width mode reads the same bits as two's complement and raises an overflow flag instead of wrapping quietly. Division is integer division and the remainder is shown beside it.