Signed Numbers Representation In Computer Systems

Representation of Numbers

Representation of Numbers In Computer Systems:

To study the representation of a number in computer science is important. Do you know how a computer deals with negative numbers, fractional numbers? You have already learnt about numbers in mathematics in early classes. There are some terminologies used while studying number systems. I would like to explain them as well. Again I tried my best to make this topic as simple as possible.
In computing numbers can either be represented as
  • Integers
  • Floating Point Numbers

Key Questions:
  • What are integers?
  • What are floating point numbers?
  • What are signed numbers?
  • What is sign magnitude system?
  • What is complement of a number?
  • What is r’s complement and (r-1)'s complement?
  • How to calculate r’s complement and (r-1)'s complement?


Integers:

It is a fixed point number, a whole number that has not any fractional part. An integer can be a positive or negative or zero. Or they can be signed numbers or unsigned numbers. Computers deal with binary numbers. In computer 32 bit signed integers are stored in the following way.

Sign bit (MSB)
1 bit long
Integer number 0-31 bits


Some examples are:
  • 10101)2
  • 4567)8
  • 88)10
  • AB)16

Floating Point Numbers:
As the name implies the number with radix point (decimal point, or binary point) that has no fixed position. A number that has fractional part. Floating point numbers can either be positive or negative. Or we can say floating point numbers can be signed numbers and unsigned numbers.

Some examples are:
  • 1.67*1012
  • 1457.781
  • 23*10-23


In computing, or science we represent fractional numbers in floating point format. It is easy to represent and easy to store by computers. There are several terms that are associated with floating point numbers. Let's have a look at them.


Normalized Notation:

Representation of floating point numbers with no leading 0s. For example 1.67*1023

0.167*1024 not a normalised number.

Single Precision Floating Point Numbers:
Single Precision is the term used in computers storage. Single precision floating point number is 32 bits long. It is stored by computers as follows:

Sign bit (MSB)
1 bit
Exponent
0-7 bits
Mantissa
0-23 bits


Double Precision Floating Point Numbers:
Another standard for floating point representation. They are 64 bits long.

Sign bit (MSB)
1 bit
Exponent
0-11 bits
Mantissa
0-52 bits

Representation of Signed Numbers:
How do you distinguish a positive and a negative number? Of course a  negative number is shown by minus (-) sign in mathematics. But in computing no symbol is used to represent the sign of a number. Computer uses binary numbers. So, MSB also represents the sign of number. 0 means positive number, 1 means negative number. So MSB represent magnitude as well as sign of number. No need of extra bit to represent the sign of a numbers. Three commonly used techniques for signed numbers are:

  • Sign Magnitude System
  • r’s complement
  • (r-1)'s complement

Sign magnitude system:

The leftmost bit represent the sign of a number. While the rest of the bits represent magnitude of the number. 0 is for positive number, while 1 is for negative number. In sign magnitude system there are 7 bits to represent the magnitude of a number (this is for an 8 bits number).  While the last and leftmost bit is reserved for representing the sign only.

Example:
10001111)2 = -15)10
00001111)2= +15)10
10001010)2 = -10)10
00001010)2 = +10)10

The magnitude bits are in true binary form (uncomplemented)  for both positive and negative numbers. In above examples magnitude bits are same for both positive and negative numbers but the sign bit is either 1 or 0.

Disadvantage: With an 8 bit number we can represent 0 to 255 (28=256 unique combinations) in decimal numbers. But in sign magnitude system we have 7 bits to represent the magnitude of a number. 27 (128 or 0-127 in base 10 or equivalent in other number systems ) unique combination can be represented. So for sign magnitude representation we need more bits.


Sign bit (MSB)
1 bit
0 to +127 / 0 to -127
0-7 bits


What is complement?

To get complement of a number is to get the opposite value of a number. For positive numbers its complement is the negative equivalent value. There are two types of complement.
  • r’s complement
  • (r-1)'s complement
Where r is the base or radix of number system.

  • For decimal (base 10) number system there is 10’s complement and 9’s (10-1)'s complement
  • For binary (base 2) number system there is 2’s complement and 1’s (2-1)'s complement
  • For octal (base 8) number system there is 8’s complement and 7’s (8-1)'s complement
  • For hexadecimal (base 16) number system there is 16’s complement and 15’s (16-1)'s complement

Complements In Decimal Number System:

9’s Complement: positive numbers in the 9’s complement system are represented the same way as we use them normally that is 25, 35 etc. However, a negative number is the 9’s complement of the corresponding positive number.

Example: 9765)10 to get the 9’s complement  or  opposite of a number take every digit and subtract it from 9.

[(9-9),(9-7),(9-6),(9-5)]=0234)10

10’s Complement: positive numbers in 10’s complement system are represented the same way as we use them normally. However, a negative number is the 10’s complement of the corresponding positive number.

Example: 9765)10 to get 10’s complement of a number first take 9’s complement and then add 1 to it.
9’s complement  0234)10
10’s complement 0235)10

Example: 12345)10 evaluate 9’s and 10’s complement.
9’s complement   87654)10
10’s complement 87655)10

Complements In Binary Number System:

1’s Complement:
Positive numbers are represented the same way as in sign magnitude system. However, negative number is the 1’s complement of the corresponding positive number.

Example +25 (00011001)2)
To get 1’s complement of a number subtract each bit by 1.
[(1-0),(1-0),(1-0),(1-1),(1-1),(1-0),(1-1)] = 11100110)2

2’s Complement:
Positive numbers are represented the same same way as in sign magnitude system. However, negative number is the 2’s complement of the corresponding positive number.

Example: +25 (00011001)2)
To get 2’s complement of a number evaluate 1’s complement and then add 1.

1’s complement 11100110)2
2’s complement 11100111)2

Example: 10101111)2 evaluate 1’s and 2’s complement

1’s complement 01010000)2
2’s complement 01010001)2

Complements In Octal Number System:


7’s Complement:
Positive numbers are represented in the same way as we discussed in decimal numbers. But how to express negative numbers. Negative number is the 7’s complement of the corresponding positive number.

Example: 6767)8 evaluate its 7’s complement
To get 7’s complement subtract each digit from 7.
[(7-6),(7-7),(7-6),(7-7)]=1010)8

8’s Complement:
It is another representation of negative numbers. Negative number is the 8’s complement of the corresponding positive number.

Example: 6767)8 evaluate its 8’s complement
To get 8’s complement of a number first evaluate 7’s complement and then add 1.

7’s complement = 1010)8
8’s complement = 1011)8

Example: 65437)8 evaluate 7’s and 8’s complement

7’s complement = 12340)8
8’s complement = 12341)8

Complements In Hexadecimal Number System:

15’s complement:
15’s complement is used to express negative numbers in hexadecimal number system. A negative number is the 15’s complement of the corresponding positive number.

Example AB456)16 evaluate its 15’s complement
To get 15’s complement of a number subtract each digit from 15
[(15-A),(15-B),(15-4),(15-5),(15-6)]=56BA9)16

16’s Complement:
It is another representation of negative numbers. A negative number is the 2’s complement of the corresponding positive number.

Example AB456)16 evaluate its 16’s complement
To get 16’s complement of a number first evaluate 15’s complement and then add 1.

15’s complement = 56BA9)16
16’s complement = 56BAA)16

Example 5678AD)16 evaluate 15’s and 16’s complement

15’s complement = A98752)16
16’s complement = A98753)16


Hexadecimal to Binary and Binary to Hexadecimal Conversion Solved Examples

Hexadecimal to Binary and Binary to Hexadecimal Conversion


The conversion between hexadecimal and binary number system is easy and straightforward task. Let's start.

Key Questions:
  • Convert binary numbers into hexadecimal numbers
  • Convert hexadecimal numbers into binary numbers
  • How to convert binary fraction into hexadecimal fraction
  • How to convert hexadecimal fraction into binary fraction

Hexadecimal numbers
00
01
02
03
04
05
06
07
Binary numbers
0000
0001
0010
1111
0100
0101
0110
0111
Hexadecimal numbers
08
09
0A
0B
0C
0D
0E
0F
Binary numbers
1000
1001
1010
1011
1100
1101
1110
1111


Binary to Hexadecimal Conversion:

Whenever converting from binary to hexadecimal numbers, start with making group of 4 bits. But why we use 4 bits? Because  4 bits represent 16 different values. Or the largest possible value for 4 bit number is 2n-1. For integers start making group of 4 from right to left.

Example 11100111101)2

0111 0011 1101

The above binary number is an 11 bit number. You make two 4 bits groups easily. For third group add zero at the leftmost position. So 3 groups of 4 bits has been made as shown above.

For fractional numbers, start making groups of 4 bits from left to right.

Example: 0.11100110111)2

0.1110 0110 1110

In the above fractional number you can easily make two groups of 4 bits, starting from left. While for third group of 4 bits we have to add a zero at the rightmost position as shown above.

Let's solve some examples so that the you understand the conversion method.

Convert the given binary number into hexadecimal number Example#01: 1111111111)2  = ?)16


Making group of 4 bits
0011 1111 1111

Binary number
0011
1111
1111
Hexadecimal number
3
F
F


Answer 1111111111)2  = 3FF)16


Convert the given binary number into hexadecimal number Example#2: 110010111010.11111111)2=?)16


Making group of 4 bits

1100 1011 1010.1111 1111


Binary number
1100
1011
1010
.
1111
1111
Hexadecimal number
C
B
A
.
F
F

Answer 110010111010.11111111)2=CBA.FF)16


 

Convert the given binary number into hexadecimal number  Example#03: 11001100110011.111000111)2= ?)16


Making group of 4 bits

0011 0011 0011 0011.1110 0011 1000

Adding two 0s on leftmost side to complete a group of 4 bits. Adding three 0s on rightmost position in order to complete a group of 4 bits.


Binary number
0011
0011
0011
0011
.
1110
0011
1000
Hexadecimal number
3
3
3
3
.
E
3
8

Answer  11001100110011.111000111)2= 3333.E38)16


Hexadecimal to Binary Conversion:

When converting from Hexadecimal to binary number pick a single hexadecimal digit and convert it to equivalent binary number. One thing you have to keep in mind that binary number should be represent in 4 bit format. For example

1)16=0001)2 right way
1)16=1)2 wrong way

Note: this is wrong while using this technique. Otherwise it is absolutely right.  
1)16=1)2

Convert the given hexadecimal number into binary number Example#01:3FF)16= ?)2


3)16=0011)2

Hexadecimal number
3
F
F
Binary number
0011
1111
1111

Answer 3FF)16= 001111111111)2


Convert the given hexadecimal number into binary number Example#02:CBA.FF)16= ?)2



Hexadecimal number
C
B
A
.
F
F
Binary number
1100
1011
1010
.
1111
1111

Answer CBA.FF)16= 110010111010.11111111)2


Convert the given hexadecimal number into binary number Example#03: 3333.E38)16= ?)2


Hexadecimal number
3
3
3
3
.
E
3
8
Binary number
0011
0011
0011
0011
.
1110
0011
1000


Answer 3333.E38)16= 11001100110011.111000111)2

Popular Posts