The 9's complement of a decimal number
The 9's complement of a decimal number is a mathematical operation that involves replacing each digit with its complement to 9. This operation is commonly used in computer science and digital arithmetic. The 9's complement operation is often used in digital arithmetic for subtraction operations using addition with the complemented number.
To find the 9's complement of a decimal number, following are the steps:
- Subtract each digit from 9.
- Write down the results of the subtractions as the digits of the 9's complement.
Few examples of finding the 9's complement of decimal numbers are given below:
Example 1: Number = 12345
Step 1: Subtract each digit from 9
9 - 1 = 8 9 - 2 = 7 9 - 3 = 6 9 - 4 = 5 9 - 5 = 4
Step 2: Write down the results:
9's Complement: 87654
Example 2: Number = 9876
Step 1: Subtract each digit from 9
9 - 9 = 0 9 - 8 = 1 9 - 7 = 2 9 - 6 = 3
Step 2: Write down the results: :
9's Complement: 123
Example 3: Number = 555
Step 1: 9 - 5 = 4, 9 - 5 = 4, 9 - 5 = 4
9's Complement: 444
Example 4: Number = 1000
Step 1: 9 - 1 = 8, 9 - 0 = 9, 9 - 0 = 9, 9 - 0 = 9
9's Complement: 8999
Example 5: Number = 420
Step 1: 9 - 4 = 5, 9 - 2 = 7, 9 - 0 = 9
9's Complement: 579
Example 6: Number = 9999
Step 1: 9 - 9 = 0, 9 - 9 = 0, 9 - 9 = 0, 9 - 9 = 0
9's Complement: 0
Example 7: Number = 735
Step 1: 9 - 7 = 2, 9 - 3 = 6, 9 - 5 = 4
9's Complement: 264
Example 8: Number = 1234
Step 1: 9 - 1 = 8, 9 - 2 = 7, 9 - 3 = 6, 9 - 4 = 5
9's Complement: 8765
Example 9: Number = 909
Step 1: 9 - 9 = 0, 9 - 0 = 9, 9 - 9 = 0
9's Complement: 90
Example 10: Number = 0
Step 1: 9 - 0 = 9
9's Complement: 9
The 10's complement
The 10's complement is a technique used in digital arithmetic to represent negative numbers. It simplifies subtraction by transforming it into addition and allows both positive and negative numbers to be represented uniformly. It involves finding the complement of a given decimal number with respect to 10. To find the 10's complement of a number, you subtract each digit from 9. Following steps are used to find the 10's complement of a decimal number:
- Subtract each digit of the number from 9.
- Add 1 to the result.
Few examples of finding the 10's complement along with the method of conversion:
Example 1: Number: 325
10's Complement: 675
Method: Subtract each digit from 9: For the first digit, 9 - 3 = 6. For the second digit, 9 - 2 = 7. For the third digit, 9 - 5 = 4.
Example 2: Number: 780
10's Complement: 220
Method: Subtract each digit from 9: For the first digit, 9 - 7 = 2. For the second digit, 9 - 8 = 1. For the third digit, 9 - 0 = 9.
Example 3: Number: 4562
10's Complement: 5438
Method: Subtract each digit from 9: For the first digit, 9 - 4 = 5. For the second digit, 9 - 5 = 4. For the third digit, 9 - 6 = 3. For the fourth digit, 9 - 2 = 7.
Repeat the same process for the remaining examples.
Example 4: Number: 912
10's Complement: 88
Example 5: Number: 1000
10's Complement: 9000
Example 6: Number: 7
10's Complement: 3
Example 7: Number: 84379
10's Complement: 15621
Example 8: Number: 12345
10's Complement: 87655
Example 9: Number: 555
10's Complement: 445
Example 10: Number: 99999
10's Complement: 1
One's complement
One's complement is a binary number representation where the negative of a number is represented by inverting all the bits (changing 0s to 1s and 1s to 0s) of its binary representation. The one's complement representation is mainly used for binary arithmetic operations on computers. Negative numbers are represented by taking the one's complement of their positive binary counterpart. Few examples of converting decimal numbers to their one's complement representation:
Method of Conversion:**
- Convert the decimal number to its binary representation.
- Invert all the bits (change 0s to 1s and 1s to 0s) to get the one's complement representation.
Conversion examples:**
Example 1:
Decimal : 7 Binary : 0111 One's Complement : 1000
Example 2:
Decimal : -5 Binary : 1011 (2's complement representation of 5) One's Complement : 0100
Example 3:
Decimal : 0 Binary : 0000 One's Complement : 1111
Example 4:
Decimal : -15 Binary : 10001 (2's complement representation of 15) One's Complement : 01110
Example 5:
Decimal : 10 Binary : 1010 One's Complement : 0101
Example 6:
Decimal : -3 Binary : 1101 (2's complement representation of 3) One's Complement : 0010
Example 7:
Decimal : 127 Binary : 1111111 One's Complement : 0000000
Example 8:
Decimal : -64 Binary : 1000000 (2's complement representation of 64) One's Complement : 0111111
Example 9:
Decimal : -9 Binary : 10111 (2's complement representation of 9) One's Complement : 01000
Example 10:
Decimal : 255 Binary : 11111111 One's Complement : 00000000
Two's complement
Two's complement is a method for representing signed integers in binary form. It involves taking the binary representation of a positive integer, inverting its bits (changing 0s to 1s and 1s to 0s), and then adding 1 to the result. the leftmost bit (the most significant bit) is used to indicate the sign of the number when dealing with two's complement. 0 represents a positive number, and 1 represents a negative number. The range of representable values depends on the number of bits used for the representation. Few examples of converting decimal numbers to their two's complement binary representation are given below:
Example 1: Converting -5
to Two's Complement
- Represent 5 in binary : 00000101
- Invert the bits : 11111010
- Add 1 : 11111011 (two's complement of -5)
Example 2: Converting -12
to Two's Complement
- Represent 12 in binary : 00001100
- Invert the bits : 11110011
- Add 1 : 11110100 (two's complement of -12)
Example 3: Converting 7
to Two's Complement (positive number)
- Represent 7 in binary : 00000111
- Pad with leading zeros to maintain the same bit length : 00000111
- This is already the two's complement of
7
(positive numbers remain the same in two's complement).
Example 4: Converting -128
to Two's Complement
- Represent 128 in binary : 10000000
- Invert the bits : 01111111
- Add 1 : 10000000 (overflow occurs, wrapping around)
Example 5: Converting -1
to Two's Complement
- Represent 1 in binary : 00000001
- Invert the bits : 11111110
- Add 1 : 11111111 (two's complement of -1)
Example 6: Converting 15
to Two's Complement (positive number)
- Represent 15 in binary : 00001111
- Pad with leading zeros to maintain the same bit length : 00001111
- This is already the two's complement of 15 (positive numbers remain the same in two's complement).
Example 7: Converting -31
to Two's Complement
- Represent 31 in binary : 00011111
- Invert the bits : 11100000
- Add 1 : 11100001 (two's complement of -31)
Example 8: Converting -64
to Two's Complement
- Represent 64 in binary : 01000000
- Invert the bits : 10111111
- Add 1 : 11000000 (two's complement of -64)
Example 9: Converting 63
to Two's Complement (positive number)
- Represent 63 in binary : 00111111
- Pad with leading zeros to maintain the same bit length : 00111111
- This is already the two's complement of 63 (positive numbers remain the same in two's complement).
Example 10: Converting -255
to Two's Complement
- Represent 255 in binary : 11111111
- Invert the bits : 00000000
- Add 1 : 00000001 (overflow occurs, wrapping around)
Binary Addition
Binary addition is a fundamental arithmetic operation in the realm of digital systems and computer science. It plays a crucial role in various computing processes, from basic calculations to complex data manipulation. Binary addition is a foundational operation in computer systems and plays a crucial role in various applications:
- Arithmetic Operations: Binary addition forms the basis for other arithmetic operations, such as subtraction, multiplication, and division.
- Data Manipulation: Computers use binary addition to manipulate data stored in memory, enabling calculations and transformations.
- Logic and Circuits: In digital logic design, binary addition is essential for building circuits that perform tasks like counting and data processing.
- Error Detection and Correction: Binary addition is used in error detection and correction codes, enhancing data reliability in communication systems.
- Binary Coded Decimal (BCD): BCD is a binary-encoded representation of decimal numbers, and binary addition is used to perform arithmetic on BCD numbers.
Binary Addition Rules
Binary addition follows similar principles to decimal addition. Just as you carry over digits in decimal addition when the sum exceeds 9, the carry over used when the sum of digits in a column is 2 or greater. The basic rules are as follows:
0 + 0 = 0: Adding two binary digits of 0 results in 0. 0 + 1 = 1: Adding 0 and 1 gives 1. 1 + 0 = 1: Adding 1 and 0 also yields 1. 1 + 1 = 0, Carry 1: Adding two 1s results in 0, with a carry of 1 to the next digit.
These rules are essential building blocks for binary addition, just as their decimal counterparts are for decimal addition.
Binary Addition Process
An example of binary addition: 1101 + 101 is given below.
1 1 0 1 (1101) + 1 0 1 (101) ------------ 1 0 1 1 0
Method of Binary addition
- Start by adding the rightmost digits (least significant bits): 1 + 1 = 0 (with a carry of 1).
- Move to the next digits: 0 + 0 + 1 (carry) = 1.
- Then: 1 + 1 = 0 (with a carry of 1).
- Finally: 1 + 1 + 1 (carry) = 1, with a carry of 1.
- The result is 10110, which is the binary equivalent of 22 in decimal.
Carrying Over in Binary Addition
Carrying over in binary addition is analogous to carrying over in decimal addition. Consider the example: 111 + 111.
1 1 1 (111) + 1 1 1 (111) ------------ 1 1 1 0
Method of Binary addition
- Start by adding the rightmost digits: 1 + 1 = 0 (with a carry of 1).
- Move to the next digits: 1 + 1 + 1 (carry) = 1, with a carry of 1.
- Then: 1 + 1 + 1 (carry) = 1, with a carry of 1.
- The result is 1110, which is 14 in decimal.
Binary Addition with Varying Lengths
Binary addition becomes more complex when dealing with numbers of different lengths. In this case, align the numbers to the right and fill empty spaces with leading zeros.
Consider: 1101 + 11.
1 1 0 1 (1101) + 1 1 (11) ------------ 1 1 1 0
Method of Binary addition
- Start with the rightmost digits: 1 + 1 = 0 (with a carry of 1).
- Move to the next digit: 0 + 1 = 1.
- Then: 1 + 1 = 0 (with a carry of 1).
- Finally: 1 + 0 (carry) = 1, with a carry of 1.
- The result is 1110, which is 14 in decimal, as expected.
Practice examples
Few more practice examples of adding binary numbers, along with the step-by-step method of conversion:
Example 1:
1101 + 1010 ------- 10111
Method:
- Start adding from the rightmost digits (least significant bit) and move left.
- Add the corresponding digits: 1 + 0 = 1, 1 + 1 = 0 with a carry of 1, 0 + 0 = 0, 1 + 1 = 0 with a carry of 1.
- Continue this process, including the carry, until you've added all the digits.
Example 2:
110 + 101 ------- 1011
Method:
- Add the digits: 0 + 1 = 1, 1 + 0 = 1, 1 + 1 = 0 with a carry of 1.
- Add the carry to the leftmost digit.
Example 3:
1111 + 1001 ------- 11000
Method:
- Add the digits: 1 + 1 = 0 with a carry of 1, 1 + 0 = 1, 1 + 0 = 1, 1 + 1 = 0 with a carry of 1.
- Add the carry to the leftmost digit.
Example 4:
1010 + 111 ------- 10001
Method:
- Add the digits: 0 + 1 = 1, 1 + 1 = 0 with a carry of 1, 0 + 1 = 1, 1 + 0 = 1.
- Add the carry to the leftmost digit.
Example 5:
1101 + 11 ------- 1110
Method:
- Add the digits: 1 + 1 = 0 with a carry of 1, 0 + 1 = 1, 1 + 1 = 0 with a carry of 1.
- Add the carry to the leftmost digit.
Example 6:
101 + 110 ------- 1011
Method:
- Add the digits: 1 + 0 = 1, 0 + 1 = 1, 1 + 1 = 0 with a carry of 1.
- Add the carry to the leftmost digit.
Example 7:
111 + 101 ------- 1100
Method:
- Add the digits: 1 + 1 = 0 with a carry of 1, 1 + 0 = 1, 1 + 1 = 0 with a carry of 1.
- Add the carry to the leftmost digit.
Example 8:
10111 + 10 ------- 11001
Method:
- Add the digits: 1 + 0 = 1, 1 + 0 = 1, 0 + 1 = 1, 1 + 0 = 1, 1 + 1 = 0 with a carry of 1.
- Add the carry to the leftmost digit.
Example 9:
1110 + 101 ------- 10011
Method:
- Add the digits: 0 + 1 = 1, 1 + 0 = 1, 1 + 1 = 0 with a carry of 1, 1 + 1 = 0 with a carry of 1.
- Add the carry to the leftmost digit.
Example 10:
110 + 110 ------- 1100
Method:
- Add the digits: 0 + 0 = 0, 1 + 1 = 0 with a carry of 1, 1 + 1 = 0 with a carry of 1.
- Add the carry to the leftmost digit.
Binary Subtraction: The one's complement method
The one's complement method is used to subtract binary numbers. In this method, you negate the second number (the subtrahend) by flipping all of its bits (changing 0s to 1s and 1s to 0s) and then add it to the first number (the minuend). The carry-over is required if any overflow to the next higher bit after performing the addition. If there's a carry-out after adding, you need to add it back to the result. Also, in the final result, ignore any carry-out beyond the leftmost bit. A few examples of binary subtraction using the one's complement method are given below:
Example 1:
Minuend: 10101 Subtrahend: 1101 Find the one's complement of the subtrahend: 0010 Add the one's complement to the minuend: 10101 + 0010 = 10101 + 2 = 10111
Example 2:
Minuend: 11010 Subtrahend: 1001 Find the one's complement of the subtrahend: 0110 Add the one's complement to the minuend: 11010 + 0110 = 11010 + 6 = 11100
Example 3:
Minuend: 11100 Subtrahend: 1011 Find the one's complement of the subtrahend: 0100 Add the one's complement to the minuend: 11100 + 0100 = 11100 + 4 = 11104
Example 4:
Minuend: 101110 Subtrahend: 11001 Find the one's complement of the subtrahend: 00110 Add the one's complement to the minuend: 101110 + 00110 = 101110 + 6 = 110000
Example 5:
Minuend: 111111 Subtrahend: 10101 Find the one's complement of the subtrahend: 01010 Add the one's complement to the minuend: 111111 + 01010 = 111111 + 10 = 1000001
Example 6:
Minuend: 110011 Subtrahend: 11100 Find the one's complement of the subtrahend: 00011 Add the one's complement to the minuend: 110011 + 00011 = 110011 + 3 = 110110
Example 7:
Minuend: 1001001 Subtrahend: 101101 Find the one's complement of the subtrahend: 010010 Add the one's complement to the minuend: 1001001 + 010010 = 1001001 + 18 = 10111011
Example 8:
Minuend: 1100100 Subtrahend: 101011 Find the one's complement of the subtrahend: 010100 Add the one's complement to the minuend: 1100100 + 010100 = 1100100 + 20 = 1101000
Example 9:
Minuend: 1110001 Subtrahend: 110011 Find the one's complement of the subtrahend: 001100 Add the one's complement to the minuend: 1110001 + 001100 = 1110001 + 12 = 1111010
Example 10:
Minuend: 1001010 Subtrahend: 10110 Find the one's complement of the subtrahend: 01001 Add the one's complement to the minuend: 1001010 + 01001 = 1001010 + 9 = 1001101
Practice examples
More examples of subtracting binary numbers using the one's complement method, along with the step-by-step conversion process:
Example 1: 101 - 11
Convert the second number to its one's complement:
11
⇒00
Add:
101 + 00 ------ 101
Example 2: 1101 - 101
Convert the second number to its one's complement:
101
⇒010
Add:
1101 + 010 ------ 1000
Example 3: 11100 - 1011
Convert the second number to its one's complement:
1011
⇒0100
Add:
11100 + 0100 ------- 100100
Example 4: 10010 - 1111
Convert the second number to its one's complement:
1111
⇒0000
Add:
10010 + 0000 ------- 10010
Example 5: 11111 - 10101
Convert the second number to its one's complement:
10101
⇒01010
Add:
11111 + 01010 -------- 101001
Example 6: 101010 - 1101
Convert the second number to its one's complement:
1101
⇒0010
Add:
101010 + 0010 -------- 101100
Example 7: 11001 - 10011
Convert the second number to its one's complement:
10011
⇒01100
Add:
11001 + 01100 -------- 100101
Example 8: 101001 - 100110
Convert the second number to its one's complement:
100110
⇒011001
Add:
101001 + 011001 -------- 100100
Example 9: 111111 - 101010
Convert the second number to its one's complement:
101010
⇒010101
Add:
111111 + 010101 -------- 1010110
Example 10: 1001010 - 10110
Convert the second number to its one's complement:
10110
⇒01001
Add:
1001010 + 01001 --------- 1011111
Binary Subtraction: two's complement method
Example 1: Subtract 10101
from 11001
.
- Convert the subtrahend to its two's complement:
- Invert all bits:
10101
becomes01010
. - Add 1:
01010
+00001
=01011
.
- Add the two's complement of the subtrahend to the minuend:
11001 (minuend) +01011 (two's complement of subtrahend) ------ 00100 (result in binary)
- The result is
00100
in binary, which is4
in decimal.
Example 2: Subtract 1110
from 10011
.
- Convert the subtrahend to its two's complement:
- Invert all bits:
1110
becomes0001
. - Add 1:
0001
+0001
=0010
.
- Add the two's complement of the subtrahend to the minuend:
10011 (minuend) + 0010 (two's complement of subtrahend) ------ 11001 (result in binary)
- The result is
11001
in binary, which is25
in decimal.
Example 3: Subtract 101
from 1100
.
- Convert the subtrahend to its two's complement:
- Invert all bits:
101
becomes010
. - Add 1:
010
+0001
=011
.
- Add the two's complement of the subtrahend to the minuend:
1100 (minuend) + 011 (two's complement of subtrahend) ------ 1011 (result in binary)
- The result is
1011
in binary, which is11
in decimal.
Example 4: Subtract 110
from 1001
.
- Convert the subtrahend to its two's complement:
- Invert all bits:
110
becomes001
. - Add 1:
001
+0001
=010
.
- Add the two's complement of the subtrahend to the minuend:
1001 (minuend) + 010 (two's complement of subtrahend) ------ 11011 (result in binary)
- The result is
11011
in binary, which is27
in decimal.
Example 5: Subtract 11001
from 11111
.
- Convert the subtrahend to its two's complement:
- Invert all bits:
11001
becomes00110
. - Add 1:
00110
+0001
=00111
.
- Add the two's complement of the subtrahend to the minuend:
11111 (minuend) + 00111 (two's complement of subtrahend) ------ 11000 (result in binary)
- The result is
11000
in binary, which is24
in decimal.
Example 6: Subtract 1010
from 11100
.
- Convert the subtrahend to its two's complement:
- Invert all bits:
1010
becomes0101
. - Add 1:
0101
+0001
=0110
.
- Add the two's complement of the subtrahend to the minuend:
11100 (minuend) + 0110 (two's complement of subtrahend) ------ 10010 (result in binary)
- The result is
10010
in binary, which is18
in decimal.
Example 7: Subtract 1111
from 10101
.
- Convert the subtrahend to its two's complement:
- Invert all bits:
1111
becomes0000
. - Add 1:
0000
+0001
=0001
.
- Add the two's complement of the subtrahend to the minuend:
10101 (minuend) + 0001 (two's complement of subtrahend) ------ 10100 (result in binary)
- The result is
10100
in binary, which is20
in decimal.
Example 8: Subtract 11010
from 101010
.
- Convert the subtrahend to its two's complement:
- Invert all bits:
11010
becomes00101
. - Add 1:
00101
+0001
=00110
.
- Add the two's complement of the subtrahend to the minuend:
101010 (minuend) + 00110 (two's complement of subtrahend) ------ 111100 (result in binary)
- The result is
111100
in binary, which is60
in decimal.
Example 9: Subtract 1101
from 11110
.
- Convert the subtrahend to its two's complement:
- Invert all bits:
1101
becomes0010
. - Add 1:
0010
+0001
=0011
.
- Add the two's complement of the subtrahend to the minuend:
11110 (minuend) + 0011 (two's complement of subtrahend) ------ 10111 (result in binary)
- The result is
10111
in binary, which is23
in decimal.
Example 10: Subtract 10100
from 111000
.
- Convert the subtrahend to its two's complement:
- Invert all bits:
10100
becomes01011
. - Add 1:
01011
+0001
=01100
.
- Add the two's complement of the subtrahend to the minuend:
111000 (minuend) + 01100 (two's complement of subtrahend) ------ 011100 (result in binary)
- The result is
011100
in binary, which is28
in decimal.
These examples demonstrate the process of subtracting binary numbers using the two's complement method.