0% found this document useful (0 votes)
14 views

Data Representation - Part II

Uploaded by

ayushchamoli6397
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Data Representation - Part II

Uploaded by

ayushchamoli6397
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Binary Representation of Numbers

- While working with numbers, you have mainly worked with integers (e.g. - +17, -23 etc.)
or with floating point numbers (e.g. - +17.015, -23.214 etc.)
- It is important to take note that integers and floating-point numbers are treated
differently in computers.
- They have different representation and are processed differently.

Binary Representation of Integers: -


- To represent an Integer, computers use a fixed number of bits.
- The commonly used bit lengths for integers are 8-bit, 16-bit, 32-bit or 64-bit.
- Besides bit lengths, there are two representation schemes for integers:
 Unsigned Integers can represent zero and positive integers.
 Signed Integers can represent zero, positive and negative integers.

Representing Unsigned Integers: -


- An unsigned integer can be either a positive integer or zero but never a negative
integer.
In the binary number system,
- An unsigned integer containing n bits can have a value between 0 and 2 n – 1 (i.e., out of
2n different values)
- An n-bit pattern can represent 2n distinct integers. An n-bit unsigned integer can
represent integers from 0 to 2n – 1, as tabulated below: -

Representing Signed Integers: -


- Signed integers can represent zero, positive integers, as well as negative integers. Three
representation schemes are available for signed integers:
 Sign-Magnitude representation
 1’s Complement representation
 2’s Complement representation

In all the above three schemes, the most-significant bit (MSB) is called the sign bit.
Sign-Magnitude representation: -
- This is the conventional form for number representation. Integers are identified by their
signs (+ or -) and a string of digits which represent the magnitude.

In sign-magnitude representation:
 The most-significant bit (MSB) is the sign bit, with value of 0 representing positive
integer and value 1 representing negative integer.
 The remaining n-1 bits represent the magnitude (absolute value) of the integer. The
absolute value of the integer is interpreted as “the magnitude of the (n-1)-bit binary
pattern”.

For example, if in a computer, the word size is 1 byte (8 bits), then

Sign-Magnitude Representation:

Drawbacks/Problems Associated with Sign-Magnitude Representation:


Major drawbacks of sign-magnitude representation are:
 There are two representation 0000 0000)2 (+0) and 1000 0000)2 (-0) for the number
zero, which could lead to inefficiency and confusion.
 Positive and negative integers need to be processed separately.
One’s Complement Representation:
One’s complement represents positive numbers by their binary equivalents (called true forms)
and negative numbers by their 1’s complements (called 1’s complement forms).

For example, 1’s complement of binary number 1001 will be 0110 and for 0011 will be 1100.

Note: To calculate 1’s complement of a binary number, just replace every 0 with 1 and every 1
with 0.

Example-

1’s Complement Representation:

Drawbacks/Limitations of One’s Complement Notation:


The drawbacks/limitations of one’s complement representation scheme are:

 There are two representations 0000 0000)2 and 1111 1111)2 for zero.
 The positive integers and negative integers need to be processed separately.
Two’s Complement Representation:
Two’s complement method represents positive numbers in their true forms i.e., their binary
equivalents and negative numbers in 2’s complement form.

Note: 2’s complement of a number is calculated by adding 1 to its 1’s complement.

Total numbers which a word of N bits can present, using 2’s complement representation, are
2N. Therefore, a 4-bit word can represent 24 = 16 numbers.

Two’s complement numbers have some very interesting characteristics. Consider a four-bit
word length. The decimal equivalents would be as shown in Table 1.7.
Looking at Table 1.7 and Fig 1.8, you can observe the following:

 There is one unique 0.


 The two’s complement of 0 is 0.
 The leftmost bit cannot be used to express quantity. It is a sign bit such that if it is a ‘1’,
the number is negative, and if it is a ‘0’, the number is positive.
 To convert a negative number to a positive number, you just need to find its two’s
complement.

Computers use 2’s Complement Representation for Signed Integers:


Out of the three representations for signed integers: sign-magnitude, 1’s complement and 2’s
complement, computers use 2’s complement in representing signed integers. This is because:

 There is only one representation for the number zero in 2’s complement, instead of two
representations in sign-magnitude and 1’s complement.
 Positive and negative integers can be treated together in addition and subtraction.
Subtraction can be carried out using the “addition logic”.

You might also like