Ones Complement Calculator - Flip Bits, Read the Signed Value
Use this ones complement calculator to enter a decimal or binary value, pick a bit width, and read back the inverted bits, the signed decimal value, and the role of the sign bit.
Ones Complement Calculator
Results
What Is a Ones Complement Calculator?
A ones complement calculator flips every bit in a binary number so you can see the negative equivalent that the encoding produces, the binary pattern the hardware actually stores, and the signed decimal value the CPU will read back.
- • Reading the negative form of a binary number: Enter a positive decimal value and immediately see the bit pattern that stands in for the negative version in a ones complement system.
- • Converting a binary string to its complement: Paste a bit string from a register dump or a textbook exercise and read back the inverted version with no manual flipping.
- • Working through a computer science homework set: Confirm a worked example from a class on signed binary representations without writing out 1s and 0s by hand.
- • Comparing bit widths for a signed range: Switch from 8 bits to 16 or 32 bits to see how the signed range of a ones complement value changes with the width.
Ones complement is one of three historical ways to represent negative integers in binary. The first bit, the most significant bit, is the sign bit: 0 means the number is positive or zero, and 1 means it is negative. To get the negative form, the encoding flips every single bit of the positive equivalent.
Type a value, pick a bit width, and the result panel shows the padded binary representation, the ones complement, the signed decimal value, and the sign bit. The calculator is interactive, so changing the bit width updates the signed range in place.
When the input arrives as a decimal value and you need it in binary, octal, or hexadecimal, the binary converter handles the same base conversions without the signed interpretation.
How the Ones Complement Calculator Works
The calculator reads the input as an unsigned integer inside the chosen bit width, subtracts that value from a row of width ones, and formats the difference back as a binary string. The result, read as a signed value, is the negative equivalent of the input.
- n: Unsigned integer value of the input, either entered directly in decimal or read from a binary string.
- width: Number of bits in the representation. The calculator accepts 4, 8, 12, 16, 32, and 64 bits.
- mask: Row of width ones (binary 111...1). Subtracting n from the mask flips every bit of n.
The subtraction (2^width − 1) − n is mathematically identical to flipping every bit, because a row of width ones is the largest value the width can hold. This is the same operation the CPU performs with a bitwise NOT, and the calculator shows it the same way the hardware does.
Decimal 87 in 8 bits
Mode: decimal, value: 87, width: 8 bits
n = 87, mask = 11111111₂ = 255. Complement = 255 − 87 = 168 = 10101000₂. The sign bit is 1, so the signed value is −87.
Binary 01010111, ones complement 10101000, signed value −87, sign bit 1.
The bit pattern 10101000 is the eight-bit ones complement of 87. The leading 1 marks the number as negative, and the magnitude is recovered by inverting the remaining 7 bits: 0101000 flips to 1010111, which equals 87, so the value is −87.
Binary 10111001 in 8 bits
Mode: binary, value: 10111001, width: 8 bits
n = 10111001₂ = 185. Complement = 11111111₂ − 10111001₂ = 01000110₂ = 70. The complement starts with 0 and represents +70.
Binary 10111001, ones complement 01000110, signed value 70, sign bit 0.
Flipping a negative bit pattern produces the positive equivalent. The complement 01000110 sits inside the signed range, so the result is the ordinary positive integer 70.
According to Wikipedia - Ones' complement, the ones complement of a binary number is obtained by inverting all of its bits, and the signed range for an n-bit representation runs from -(2^(n-1) - 1) to (2^(n-1) - 1).
The bitwise NOT behind this tool is one of the operations that the binary operations calculator exposes, alongside AND, OR, XOR, add, subtract, multiply, and divide, on the same two-operand form.
Key Concepts Behind Ones Complement
These four ideas cover what the bit flip actually means, why the encoding has a strange range, and how ones complement compares to its two more common relatives.
Bitwise NOT as a complement
Inverting every bit of a binary value is the same as subtracting it from a row of ones, so the ones complement is the bitwise NOT written as a signed integer.
Sign bit and the most significant position
The first bit of the word is the sign bit. A 0 means the number is non-negative and a 1 means it is negative, with the magnitude stored in the remaining bits.
Symmetric range and the two zeros
Ones complement has two encodings for zero, the all-zeros pattern and the all-ones pattern, which keeps the signed range symmetric from −127 to +127 at the cost of a duplicate zero.
Ones complement vs two's complement
Two's complement also uses a sign bit but does not flip every bit, which removes the second zero and lets the encoding do ordinary binary addition. Ones complement needs an end-around carry to add correctly.
The complement is simple to compute but the consequences show up everywhere. The sign bit drives the signed decimal value, the duplicate zero breaks the rule that zero has only one representation, and the encoding requires an end-around carry to add two negative numbers correctly.
For the related question of how the encoding behaves under subtraction, the binary subtraction calculator walks through the two's complement rule that most CPUs actually use in hardware.
How to Use This Calculator
Pick a mode, choose a bit width, and type a value. The result panel updates as you change any field, so you can sweep through inputs to see the pattern.
- 1 Pick the input mode: Choose Decimal integer when you have a base-10 value or Binary string when you are pasting a register dump or a bit string from a homework set.
- 2 Choose a bit width: Pick 4, 8, 12, 16, 32, or 64 bits. The signed range label updates to match, so you know which values fit before you type them.
- 3 Enter the value: Type a non-negative integer for decimal mode or a string of 0s and 1s for binary mode. The binary input must not exceed the chosen bit width.
- 4 Read the binary representation: Confirm the padded binary string in the result panel. The number of digits equals the chosen bit width, with leading zeros added on the left when the value is short.
- 5 Read the ones complement: The complement row shows the inverted bit pattern. The most significant bit of this row is the sign bit the encoding uses.
- 6 Read the signed value: Use the signed decimal value to confirm the negative equivalent. If the sign bit is 1 and the pattern is not all ones, the signed value is negative.
Type 87 in decimal mode with 8 bits selected. The result panel shows binary 01010111, ones complement 10101000, signed value -87, and sign bit 1. The complement and the signed value match the example in the worked examples card above.
Once the ones complement is in hand and you need the sum of two such values, the binary addition calculator handles the column-by-column addition with carry that the encoding requires.
Benefits of Using the Ones Complement Calculator
The bit flip itself is one keystroke in a calculator app, but the steps around it are the part that costs time. The ones complement calculator removes the bookkeeping.
- • Avoids manual bit flipping errors: Transcribing a long binary string and flipping each bit by hand is the classic place to lose a digit. The calculator flips every position at once and shows the new string padded to the chosen width.
- • Computes the signed value automatically: Reading the complement as a signed integer is a separate step that the calculator does for you, including the negative zero case.
- • Handles every common bit width: Switching between 8, 12, 16, 32, and 64 bits updates the signed range label, the validation, and the binary string length in the same view.
- • Accepts both decimal and binary entry: Decimal mode is convenient for textbook numbers, binary mode is convenient for register dumps, and the result panel keeps the two views consistent.
- • Surfaces the sign bit as a separate field: The sign bit row makes it obvious whether the complement should be read as positive or negative, which is the most common question in a ones complement exercise.
Use the calculator while working through a signed representations chapter, or keep it open while reading a CPU manual that describes bitwise NOT on a fixed-width register. The result panel covers the two outputs that always need to be on hand.
When the bit pattern is easier to read as base-16, the binary to hexadecimal calculator groups the binary digits into nibbles and renders the matching hex string.
Factors That Affect the Ones Complement
Three inputs change the result the calculator returns, and the limitations below cover the assumptions the encoding itself makes.
Bit width controls the mask
The mask is 2^width − 1, so widening the representation adds new bits to the flip. Switching from 8 bits (255) to 16 bits (65535) directly changes which decimal values fit.
The most significant bit is reserved for the sign
One bit is always used to flag the sign, so an 8-bit representation only has 7 bits of magnitude. The signed range reads -127 to +127 instead of -128 to +127.
Decimal and binary entry share one pipeline
Binary mode converts the string to an unsigned integer first, then runs the same (2^width − 1) − n step. The result is consistent across modes.
- • Ones complement is not the encoding modern CPUs use for signed integers. Most processors use two's complement today, so a ones complement value is rarely what the hardware actually computes.
- • The encoding has two representations of zero (000...0 and 111...1). The calculator reports this in the result panel as a negative-zero note, but downstream code that expects a single zero has to handle both bit patterns.
- • Adding two ones complement numbers produces a result that needs an end-around carry. The calculator only flips bits, so users who need the sum should pair it with a binary addition calculator.
The bit width is the only knob the user has to choose. The signed range and the validation both come from it, so changing the bit width should be the first thing to try when a value does not fit.
According to Wikipedia - Signed number representations, signed number representations section, ones complement is one of three historical encodings for negative integers in binary, alongside sign-and-magnitude and two's complement.
If the wider context is hexadecimal arithmetic instead of pure binary, the hex calculator moves between hex, decimal, and binary in a single form.
Frequently Asked Questions
Q: What is a ones complement calculator?
A: A ones complement calculator flips every bit of a binary number at a chosen bit width and shows the result as a binary string, a signed decimal value, and the sign bit. The flip produces the negative equivalent of the input inside a ones complement encoding.
Q: How do you calculate the ones complement of a binary number?
A: Pick a bit width, write the input as a binary string padded with leading zeros to that width, and then change every 0 to a 1 and every 1 to a 0. Equivalently, compute (2^width − 1) − n, where n is the unsigned value of the input.
Q: What is the ones complement of 7?
A: In 8 bits, 7 is written as 0000 0111. The ones complement is 1111 1000, read back as the signed value −7 because the most significant bit is 1 and inverting the remaining 7 bits (1111000) yields 0000111, which equals 7.
Q: Why does ones complement have two representations of zero?
A: Ones complement reserves the most significant bit as the sign bit, so 0000 0000 reads as positive zero and 1111 1111 reads as negative zero. Both patterns represent 0, which is one reason modern CPUs use two's complement.
Q: What is the range of a signed 8-bit ones complement number?
A: A signed 8-bit ones complement number runs from −127 to +127. The sign bit costs one position on each side, and the encoding gives up an extra slot for negative zero (1111 1111) instead of reaching −128, so the range stays symmetric at the price of a duplicate zero.
Q: How is ones complement different from two's complement?
A: Ones complement flips every bit of the positive form, which gives a second zero and forces addition to use an end-around carry. Two's complement flips every bit and then adds 1, which removes the second zero and lets the encoding use ordinary binary addition.