Different ways to represent Signed Integer
Last Updated :
07 Jan, 2024
A signed integer is an integer with a positive ‘+’ or negative sign ‘-‘ associated with it. Since the computer only understands binary, it is necessary to represent these signed integers in binary form.
In binary, signed Integer can be represented in three ways:
- Signed bit.
- 1’s Complement.
- 2’s Complement.
Let us see why 2’s complement is considered to be the best method.
Signed bit Representation
In the signed integer representation method the following rules are followed:
1. The MSB (Most Significant Bit) represents the sign of the Integer.
2. Magnitude is represented by other bits other than MSB i.e. (n-1) bits where n is the no. of bits.
3. If the number is positive, MSB is 0 else 1.
4. The range of signed integer representation of an n-bit number is given as –(2^{n-1}-1) to (2)^{n-1}-1.
Example:
Let n = 4
Range:
–(2^{4-1}-1) to 2^{4-1}-1
= -(2^{3}-1) to 2^{3}-1
= -(7) to+7
For 4 bit representation, minimum value=-7 and maximum value=+7
Signed bit Representation:
|
Positive Numbers
|
| Sign |
Magnitude |
Decimal Representation |
| 0 |
0 |
0 |
0 |
+0 |
| 0 |
0 |
0 |
1 |
+1 |
| 0 |
0 |
1 |
0 |
+2 |
| 0 |
0 |
1 |
1 |
+3 |
| 0 |
1 |
0 |
0 |
+4 |
| 0 |
1 |
0 |
1 |
+5 |
| 0 |
1 |
1 |
0 |
+6 |
| 0 |
1 |
1 |
1 |
+7 |
|
Negative Numbers
|
| Sign |
Magnitude |
Decimal Representation |
| 1 |
0 |
0 |
0 |
-0 |
| 1 |
0 |
0 |
1 |
-1 |
| 1 |
0 |
1 |
0 |
-2 |
| 1 |
0 |
1 |
1 |
-3 |
| 1 |
1 |
0 |
0 |
-4 |
| 1 |
1 |
0 |
1 |
-5 |
| 1 |
1 |
1 |
0 |
-6 |
| 1 |
1 |
1 |
1 |
-7 |
Drawbacks:
1. For 0, there are two representations: -0 and +0 which should not be the case as 0 is neither –ve nor +ve.
2. Out of 2^n bits for representation, we are able to utilize only 2^{n-1} bits.
3. Numbers are not in cyclic order i.e. After the largest number (in this, for example, +7) the next number is not the least number (in this, for example, +0).
4. For negative numbers signed extension does not work.
Example:
Signed extension for +5

Signed extension for -5

5. As we can see above, for +ve representation, if 4 bits are extended to 5 bits there is a need to just append 0 in MSB.
6. But if the same is done in –ve representation we won’t get the same number. i.e. 10101 ≠ 11101.
1’s Complement representation of a signed integer
In 1’s complement representation the following rules are used:
1. For +ve numbers the representation rules are the same as signed integer representation.
2. For –ve numbers, we can follow any one of the two approaches:
- Write the +ve number in binary and take 1’s complement of it.
1’s complement of 0 = 1 and 1’s complement of 1 = 0
Example:
(-5) in 1’s complement:
+5 = 0101
-5 = 1010
- Write Unsigned representation of 2^n-1-X for –X.
Example: –X = -5 for n=4 2^4-1-5=10 ->1010(Unsigned)
3. The range of 1’s complement integer representation of n-bit number is given as –(2^{n-1}-1) to 2^{n-1}-1.
1’s Complement Representation:
| 0 |
0 0 0 |
+0 |
| 0 |
0 0 1 |
+1 |
| 0 |
0 1 0 |
+2 |
| 0 |
0 1 1 |
+3 |
| 0 |
1 0 0 |
+4 |
| 0 |
1 0 1 |
+5 |
| 0 |
1 1 0 |
+6 |
| 0 |
1 1 1 |
+7 |
| Negative Numbers |
| Sign |
Magnitude |
Number |
| 1 |
0 0 0 |
-7 |
| 1 |
0 0 1 |
-6 |
| 1 |
0 1 0 |
-5 |
| 1 |
0 1 1 |
-4 |
| 1 |
1 0 0 |
-3 |
| 1 |
1 0 1 |
-2 |
| 1 |
1 1 0 |
-1 |
| 1 |
1 1 1 |
-0 |
Drawbacks:
- For 0, there are two representations: -0 and +0 which should not be the case as 0 is neither –ve nor +ve.
- Out of 2^n bits for representation, we are able to utilize only 2^{n-1} bits.
Merits over Signed bit representation:
1. Numbers are in cyclic order i.e. after the largest number (in this, for example, +7) the next number is the least number (in this, for example, -7).
2. For negative number signed extension works.
Example: Signed extension for +5

Signed extension for -5

3. As it can be seen above, for +ve as well as -ve representation, if 4 bits are extended to 5 bits there is a need to just append 0/1 respectively in MSB.
2’s Complement representation
In 2’s Complement representation the following rules are used:
1. For +ve numbers, the representation rules are the same as signed integer representation.
2. For –ve numbers, there are two different ways we can represent the number.
- Write an unsigned representation of 2^n-X for –X in n-bit representation.
Example:
(-5) in 4-bit representation
2^4-5=11 -→1011(unsigned)
- Write a representation of +X and take 2’s Complement.
To take 2’s complement simply take 1’s complement and add 1 to it.
Example:
(-5) in 2’s complement
(+5) = 0101
1’s complement of (+5) = 1010
Add 1 in 1010: 1010+1 = 1011
Therefore (-5) = 1011
3. Range of representation of n-bit is –(2^{n-1} ) to (2)^{(n-1)-1}.
2’s Complement representation (4 bits)

Merits:
- No ambiguity in the representation of 0.
- Numbers are in cyclic order i.e. after +7 comes -8.
- Signed Extension works.
- The range of numbers that can be represented using 2’s complement is very high.
Due to all of the above merits of 2’s complement representation of a signed integer, binary numbers are represented using 2’s complement method instead of signed bit and 1’s complement.
Similar Reads
Different ways to represent Signed Integer
A signed integer is an integer with a positive '+' or negative sign '-' associated with it. Since the computer only understands binary, it is necessary to represent these signed integers in binary form. In binary, signed Integer can be represented in three ways: Signed bit.1’s Complement.2’s Complem
4 min read
Detect if two integers have opposite signs
Given two signed integers, write a function that returns true if the signs of given integers are different, otherwise false. For example, the function should return true -1 and +100, and should return false for -100 and -200. The function should not use any of the arithmetic operators. Let the given
8 min read
String to Integer - Write your own atoi()
Given a string s, the task is to convert it into integer format without utilizing any built-in functions. Refer the below steps to know about atoi() function. Cases for atoi() conversion: Skip any leading whitespaces.Check for a sign ('+' or '-'), default to positive if no sign is present.Read the i
8 min read
Swift - Integer, Floating-Point Numbers
Integers are whole numbers that can be negative, zero, or positive and cannot have a fractional component. In programming, zero and positive integers are termed as “unsigned”, and the negative ones are “signed”. Swift provides these two categories in the form of 8-bit, 16-bit, 32-bit and 64-bit form
2 min read
Convert a number into negative base representation
A number n and a negative base negBase is given to us, we need to represent n in that negative base. Negative base works similar to positive base. For example in base 2 we multiply bits to 1, 2, 4, 8 and so on to get actual number in decimal. In case of base -2 we need to multiply bits with 1, -2, 4
6 min read
Floating Point Representation - Basics
There are posts on representation of floating point format. The objective of this article is to provide a brief introduction to floating point format. The following description explains terminology and primary details of IEEE 754 binary floating-point representation. The discussion confines to singl
10 min read
Binary Representations in Digital Logic
In the digital system of logic, binary forms have core functions with respect to data processing. Binary numbers systems in which only two states are possible-0 and 1 are used in digital circuits for mathematical computations for storing information as well as information transmission. Such techniqu
8 min read
Representation of Negative Binary Numbers
In computer systems, binary numbers use only two symbols: 0 and 1. Unlike decimal numbers, binary numbers cannot include a plus (+) or minus (-) symbol directly to denote positive or negative values. Instead, negative binary numbers are represented using specific methods that incorporate a special b
3 min read
Basics of Signed Binary numbers of ranges of different Datatypes
Core concepts of Signed Binary Numbers And Explanation of Ranges of Different Datatypes. If I would ask what is the value of (1000 0000)2 in decimal then certainly two ambiguous answers will come up (-128)10 and (+128)10 . The answer is really ambiguous as both answers are correct. So the concept of
4 min read
Difference between Signed magnitude and 2's complement
While learning Binary Number Representation in Computing, you are going to face two terms. These are the Signed Magnitude and 2's Complement. Both of these are required to represent the positive and negative Binary Numbers, but still, there are many differences. In this article, we are going to disc
4 min read
1's and 2's complement of a Binary Number
Given a Binary Number as a string, print its 1's and 2's complements. 1’s complement of a binary number is another binary number obtained by toggling all bits in it, i.e., transforming the 0 bit to 1 and the 1 bit to 0.In the 1's complement format , the positive numbers remain unchanged . The negati
9 min read
Program to construct a DFA to check if a given integer is unsigned or not
Given a string S that represents an integer, the task is to check if the given string S represents an unsigned integer or not by constructing the DFA. If the given string represents an unsigned integer, then print "Unsigned integer". Otherwise, print "Not an unsigned integer". Examples: Input: S = "
10 min read
Bitwise Complement Operator (~ tilde)
Pre-requisite:Bitwise Operators in C/ C++Bitwise Operators in Java The bitwise complement operator is a unary operator (works on only one operand). It takes one number and inverts all bits of it. When bitwise operator is applied on bits then, all the 1's become 0's and vice versa. The operator for t
3 min read
Partition negative and positive without comparison with 0
Given an array of n integers, both negative and positive, partition them into two different arrays without comparing any element with 0. Examples: Input : arr[] = [1, -2, 6, -7, 8] Output : a[] = [1, 6, 8] b[] = [-2, -7] Algorithm: Initialize two empty vectors. Push the first element of the array in
8 min read
Compute the integer absolute value (abs) without branching
We need not to do anything if a number is positive. We want to change only negative numbers. Since negative numbers are stored in 2's complement form, to get the absolute value of a negative number we have to toggle bits of the number and add 1 to the result.For example -2 in a 8 bit system is store
7 min read
Bitwise Right Shift Operators in Java
In C/C++ there is only one right shift operator '>>' which should be used only for positive integers or unsigned integers. Use of the right shift operator for negative numbers is not recommended in C/C++, and when used for negative numbers, the output is compiler dependent. Unlike C++, Java su
2 min read
Program to check if a number is Positive, Negative, Odd, Even, Zero
Given a number n, the task is to check whether the given number is positive, negative, odd, even, or zero. Method 1 : A number is positive if it is greater than zero. We check this in the expression of if.If it is False, the number will either be zero or negative.This is also tested in subsequent ex
15 min read
Check if a number is positive, negative or zero using bit operators
Given a number N, check if it is positive, negative or zero without using conditional statements.Examples: Input : 30 Output : 30 is positive Input : -20 Output : -20 is negative Input: 0 Output: 0 is zero The signed shift n>>31 converts every negative number into -1 and every other into 0. Wh
5 min read
Sign of the product of a Array
Given an integer array arr[] of size N. Let P is the product of all elements in the array. Return 1 if P is positive, 0 if P is equal to 0, and -1 if P is negative. Examples: Input: arr[] = [-1, -2, -3, -4, 3, 2, 1]Output: 1Explanation: The product of all elements in the array is 144 which is positi
4 min read