### Introduction

• A complement number is a mathematical concept used in various number systems, including binary, octal, decimal, and hexadecimal to represent negative numbers and perform arithmetic operations.

### Definition

• In digital systems, the complement of a number refers to the binary representation of the number’s inverse with respect to a base.
• The complement numbers refer to the inverse representation of a binary number.

### Characteristics

• Complement numbers are essential for computer arithmetic, especially in representing and manipulating negative integers.
• They allow efficient handling of arithmetic operations and minimize the complexity of hardware implementations for addition and subtraction.

### Types

• There are two commonly used complements: the one’s complement and the two’s complement.

• One’s Complement(1’s):

• The one’s complement of a binary number is obtained by flipping/reversing all the bits (changing 0s to 1s and 1s to 0s).
• One’s complement is often used for error detection and correction in digital systems.
• It is the bitwise negation of the original number.
• For example:
• Original number: 101101
• One’s complement(1’s) : 010010
• The ones’ complement has a drawback called the “ones’ complement arithmetic” problem, where addition and subtraction of numbers require extra steps to handle end-around carry.
• Two’s Complement(2’s):
• The two’s complement of a binary number is used in computing for signed number representation.
• It is obtained by adding 1 to the one’s complement of the number.
• The two’s complement representation allows both positive and negative numbers to be represented.
• In the two’s complement representation, arithmetic operations like addition and subtraction can be performed with regular binary arithmetic. The leftmost bit indicates the sign of the number, where `0` represents a positive number and `1` represents a negative number.
• In the two’s complement representation, the leftmost bit is the sign bit (0 for positive, 1 for negative), and the remaining bits represent the magnitude of the number.
• Two’s complement is widely used in computer arithmetic because it simplifies addition and subtraction operations and allows negative numbers to be represented without a separate sign bit.
• The two’s complement representation is widely used because it simplifies arithmetic operations.
• To calculate the two’s complement:
• Find the one’s complement of the given number.
• Add 1 to the least significant bit (LSB) of the one’s complement result and finally, we got the output of 2’s.
• For example:
• Original number: 101101
• One’s complement: 010010
• Two’s complement: 010011 (one’s complement + 1)

### Use

• Complement numbers are used in digital computers in order to simplify the subtraction operation and for logical manipulations.
Categories: Computer Organization