Showing posts with label Representation of Numbers. Show all posts
Showing posts with label Representation of Numbers. Show all posts

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


Popular Posts