# Signed Representation of Binary Numbers

**Binary numbers signed representation**: Here, we are going to learn about the **signed representation of the Binary Numbers**.

Submitted by Saurabh Gupta, on October 24, 2019

**Prerequisite:** Number systems

Until now, we have only talked about positive numbers and have already discussed their mathematical operations. But there also exists negative numbers in the number system, in this article we are going to learn about **how to represent negative numbers in the binary format?**

## Signed Numbers

In decimal number system, we have (**+**) sign to represent the positive number and (**-**) sign to represent a negative number. But in digital logic, we have two symbols **0** and **1**, so we use these symbols to **represent the sign of the number**.

There are two ways of **representing signed numbers**,

- Signed Magnitude Form
- Complement Form

### 1) Signed Magnitude Form

In signed magnitude form, an additional bit is placed to the extreme left (MSB) of the number to represent the sign; thus, it is known as the sign bit.

We use 0 to represent the positive numbers and 1 to represent the negative numbers. The extra bit is isolated from the magnitude of binary numbers using a comma.

Under the signed-magnitude system, a great amount of manipulation is required to add a positive number to a negative number. Thus, representation is possible but still, it is impractical in nature.

**Example1: Represent 13 and -13 in signed magnitude form**

**Solution:**

(13)_{10}= (0,1101)_{2}sign-bit 0 is used to represent the positive number (-13)_{10}= (1,1101)_{2}sign-bit 1 is used to represent the negative number

**Complement Form:** Since performing arithmetic operations using a signed magnitude form is very complex. Digital computers use the complement form to perform these calculations.

There are two complement forms - 1's complement form and 2's complement form.

If the number is positive then, the magnitude is represented in its true binary form and a sign bit 0 is added to the LHS of the MSB. For a positive number, the representation is the same in signed magnitude, 1's and 2's complement form.

The advantage of using a complement form to perform arithmetic operations is the reduction in the hardware. Instead, of having separate hardware for addition and subtraction only additional adders are needed.

### 1's Complement Representation

The 1's complement of a number can be obtained by replacing each **"0 bit with 1 bit"** and **"1 bit with 0 bit"** in the binary number.

**Example: Represent (-15) _{10} in its 1's complement form**

**Solution:**

(15)_{10} in binary form can be represented as (1111)_{2}.

Now, to represent its negative sign, we will add a sign bit 1.

Thus, (-15)_{10} = (1,1111)_{2}. To represent it in 1's complement form, we will replace each 1 with 0 (excluding the sign bit, because if we replace sign bit then its sign will be changed to positive which is not correct). Therefore,

### 2's Complement Representation

We can get the 2's complement of a number by finding the 1's complement of number and adding 1 to the LSB of the respective 1's complement.

**Example: Represent (-15) _{10} in its 2's complement form.**

**Solution:**

As we have discussed above, the 1's complement representation of (-15)_{10} is given as **10000**. Now, we have to add a bit 1 to the LSB in the above 1's complement form i.e., we will get,

Which is the required 2's complement representation of (-15)_{10}.

**Example: Represent (-51) _{10} in its signed magnitude, 1's complement and 2's complement form.**

**Solution:**

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions