How to Find One’s Complement
It is simple to find the one’s complement of a binary number. For instance, let us go through this using a particular binary number for clarity.
Let us suppose that we have 11001100 as a binary number. The one’s complement of this number can be found by changing each bit. Here is how:
-
Initial Number: 11001100
-
Flipping All Bits:
-
For the first bit being 1, it changes to 0.
-
The second bit is also 1; hence, it becomes zero.
-
The third bit is however 0 and thus becomes one.
- You can follow this trend for every other bit after the above steps.
Once all bits have been flipped in the same manner, its ones’ complement will be 00110011 after which its representation will look like an inverted code word of two's complement method with any negative numbers converted into positive ones.
By inverting all bits, the method ensures that all the bits are inverted which makes it very important when working with negative numbers in binary arithmetic.
Examples
Let's look at a few more examples to better understand one's complement.
Example 1
Binary number: 1101
One's complement: 0010
Example 2
Binary number: 0001101
One's complement: 1110010
Example 3
Binary number: 1000000
One's complement: 0111111
In each example, we simply invert all the bits of the binary number to find its one's complement. This process remains the same regardless of the number of bits in the binary number.
Representation in Signed Magnitude
One’s complement is not just about flipping bits but also has an important role to play in computer systems regarding representation of numbers, especially signed magnitude. This is a method that represents binary forms of both positive and negative numbers.
In signed magnitude representation, the most significant bit (MSB) of a binary number determines whether it is positive or negative. Here’s how:
-
When the MSB is 0, then the number is a positive one.
- But when the MSB equals 1, then the number itself must be negative.
To make it clearer, let us take for instance this binary number 10010110 using signed magnitude:
-
The presence of 1 in its MSB suggests that it is a negative figure.
-
What remains are these bits “0010110” representing its magnitudes.
This system shows you that one’s complement often allows you to switch between positive and negative versions of a number. For example, to find out –0101011 (which is plus), you would flip all bits thus making them 1010100 meaning that they are in their negative form in terms of signed magnitude.
This method helps in understanding binary numbers as well as performing various computations such as arithmetic operations and data storage.
Uses of 1's Complement
-
Arithmetic Operations: One's complement is very important when it comes to arithmetic operations but most importantly, in subtracting binary numbers. When we want to subtract a number using one’s complement, we will add the ones’ complement of that number to another and finally plus 1 to the answer which is known as end-around carry. This way, it simplifies subtraction in digital circuits.
-
Error Detection: One's complement is used for error detection techniques such as ones' complement checksum. Here, data is divided into fixed-size blocks and then the ones’ complements are calculated for each block. The ones’ complements sum all of them up completely and final ones’ feedback on sum has got checksums used. By recalculating its check sum & comparing it again with the received check sum, the receiver can be able to verify if his or her data was sent perfectly.
-
Analog-to-Digital Converters (ADCs): Certain types of ADCs like successive approximation ADC use one’s complement. In this type of ADC, the next approximation is determined by using one’s complement of previous approximation which helps in converging towards a digital representation of an analogue input signal.
- Signed Number Representation: As mentioned earlier, one's complement is one of the methods used to represent signed numbers in binary form. It provides a way to represent negative numbers in computer systems and digital circuits.
Frequently Asked Questions
What is the main difference between one's complement and two's complement?
One's complement inverts all bits, while two's complement inverts bits and adds 1. Two's complement is more widely used due to its arithmetic advantages.
Can one's complement represent all integers?
No, one's complement has a limited range and two representations for zero, making it less efficient than two's complement for representing integers.
Is one's complement still used in modern computer systems?
While one's complement has some applications, two's complement has largely replaced it in modern computer systems due to its advantages in arithmetic operations.
Conclusion
In this article, we have learned about the concept of one's complement, a method for representing negative numbers in binary form. We discussed how to find the one's complement of a binary number by inverting all its bits. We also explored the representation of one's complement in signed magnitude and its uses in computer systems, such as arithmetic operations, error detection, and analog-to-digital converters.
You can refer to our guided paths on the Coding Ninjas. You can check our course to learn more about DSA, DBMS, Competitive Programming, Python, Java, JavaScript, etc. Also, check out some of the Guided Paths on topics such as Data Structure andAlgorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc., as well as some Contests, Test Series, and Interview Experiences curated by top Industry.