Unit-1-Data-Representation.pdf - Genuine Notes

59
CHAPTER 1: DATA REPRESENTATION Nipun Thapa https://genuinenotes.com

Transcript of Unit-1-Data-Representation.pdf - Genuine Notes

CHAPTER 1:

DATA REPRESENTATION Nipun Thapa

https://genuinenotes.com

Data Representation Data :

• It refers to the symbols that represent people, events, things, and ideas. Data can be a name, a number, the colors in a photograph, or the notes in a musical composition.

• The term “data” refers to factual information used for analysis or reasoning.

Nipun Thapa / Computer Organization 2 https://genuinenotes.com

Data Representation.. Data Representation

• It refers to the form in which data is stored, processed, and transmitted.

• Devices such as smartphones, iPods, and computers store data in digital formats that can be handled by electronic circuitry (motherboard).

• Digitization is the process of converting information, such as text, numbers, photo, or music, into digital data that can be manipulated by electronic devices.

• The Digital Revolution has evolved through four phases, beginning with big, expensive, standalone computers, and progressing to today’s digital world in which small, inexpensive digital devices are everywhere.

Nipun Thapa / Computer Organization 3 https://genuinenotes.com

Data Types The data types found in the registers of digital computers may be classified as being one of the following

categories:

1. Numbers used in arithmetic computation, 2. Letters of the alphabet used in data processing, 3. Other discrete symbols used for specific purposes.

Data are numbers and other binary-coded information that are operated on to achieve required computational results.

Nipun Thapa / Computer Organization 4 https://genuinenotes.com

Data Representation • The 0s and 1s used to represent digital data are referred

to as binary digits — from this term we get the word bit that stands for binary digit.

• A bit is a 0 or 1 used in the digital representation of data. • In digital computers, the user input is first converted and

transmitted as electrical pulses that can be represented by two unique states ON and OFF. • The ON state may be represented by a “1” and the off

state by a “0”.The sequence of ON’S and OFF’S forms the electrical signals that the computer can understand.

Nipun Thapa / Computer Organization 5 https://genuinenotes.com

Data Representation

Nipun Thapa / Computer Organization 6 https://genuinenotes.com

Representing Numbers • Numeric data consists of numbers that can be used in

arithmetic operations. • Digital devices represent numeric data using the binary

number system, also called base 2.

Nipun Thapa / Computer Organization 7 https://genuinenotes.com

Number System Decimal • Base, or radix (r) = 10 • 10 symbols: 0,1,2,3,4,5,6,7,8,9 • E.g. 630.5 = 6*102 + 3*101 + 0*100 + 5*10-1

Nipun Thapa / Computer Organization 8 https://genuinenotes.com

Decimal

Nipun Thapa / Computer Organization 9 https://genuinenotes.com

Decimal

Nipun Thapa / Computer Organization 10 https://genuinenotes.com

Decimal

Nipun Thapa / Computer Organization 11 https://genuinenotes.com

Decimal

Nipun Thapa / Computer Organization 12 https://genuinenotes.com

Number System Binary

• r = 2 • 2 symbols: 0,1 • E.g. 110010.01 = 1*25 + 1*24 + 0*23 + 0*22 + 1*21 + 0*20 + 0*2-1 + 1*2-2

-The binary number system only has two digits: 0 and 1. -No numeral like 2 exists in the system, so the number “two” is represented in binary as 10 (pronounced “one zero”).

Nipun Thapa / Computer Organization 13 https://genuinenotes.com

Binary

Nipun Thapa / Computer Organization 14 https://genuinenotes.com

Number System Octal

• r = 8 • 8 symbols: 0,1,2,3,4,5,6,7

• E.g. (736.4)8 = 7*82 + 3*81 + 6*80 + 4*8-1

Nipun Thapa / Computer Organization 15 https://genuinenotes.com

Octal

Nipun Thapa / Computer Organization 16 https://genuinenotes.com

Number System • Hexadecimal • r = 16 • 16 symbols: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F • E.g. A9D = A*162 + 9*161 + D*160

The hexadecimal numeral system, often shortened to "hex", is a numeral system made up of 16 symbols (base 16). The standard numeral system is called decimal (base 10) and uses ten symbols: 0,1,2,3,4,5,6,7,8,9. Hexadecimal uses the decimal numbers and six extra symbols.

Nipun Thapa / Computer Organization 17 https://genuinenotes.com

Conversion I. Base r to decimal

• Multiply each coefficient with corresponding power of r and add. II. Decimal to base r

• Divide by base r and collect remainder upwards. • Converting decimal fraction to binary, multiplication is used instead

of division. • And, integers are calculated instead of remainders. • Those remainders are collected downwards. • E.g. (0.625)10 = (?)2

Integer Fraction Coefficient 0.625*2 1 0.25 1

0.25*2 0 0.5 0

0.5*2 1 0 1

Nipun Thapa / Computer Organization 18 https://genuinenotes.com

Conversion II. Decimal to base r

• Therefore, (0.625)10 = (0.101)2 • H/W, (65.553)10 = (?)2

III. Binary to octal (hexadecimal) & vice versa • Conversion from binary to octal (hexadecimal) is accomplished by

partitioning the binary number into group of 3 (for octal) or 4 (for hexadecimal) digits each starting from binary point (.) & proceeding to the left and to the right.

• E.g. (1 101 001 . 111)2 = (151.7)8 (0110 1001 . 1101 0)2 = (69.D)16 • Converting from octal (hexadecimal) to binary is done by process in

reverse above. • E.g. (673.124)8 = (110 111 011 . 001 010 100)2 (306.D)16 = (11 0000 0110 . 1101)2

Nipun Thapa / Computer Organization 19 https://genuinenotes.com

Conversion 1. Binary to decimal

e.g. 1110012 = 1x25+1x24+1x23+0x22+0x21+1x20 = 5710 2.Octal to Decimal

e.g. 378 = 3×81+7×80 = 24+7 = 3110 3.Hexadecimal to Decimal

E.g. C916 : 9 = 9 * (16 ^ 0) = 9 C = 12 * (16 ^ 1) = 192 then, we add the results : 192 + 9 = 20110

Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Nipun Thapa / Computer Organization 20 https://genuinenotes.com

Conversion 3.Hexadecimal to Decimal

e.g. (ABC)16 : C = 12 * (16 ^ 0) =12 B = 11 * (16 ^ 1) =176 A = 10 * (16 ^ 2) = 2560

Then, we add the results. 2560 + 176 + 12 = 274810 decimal Test Yourself!

• Convert Hex AF, ACD, AB2 and FF to base 10 • Answers are 17510, 276510, 273810, and 25510 respectively.

Nipun Thapa / Computer Organization 21 https://genuinenotes.com

Conversion 4.Decimal to Binary

Convert 1310 to binary

Division

by 2 Quotient Remainder Bit #

13/2 6 1 0 6/2 3 0 1 3/2 1 1 2 1/2 0 1 3

So 1310 = 11012

So 17410 = 101011102

Nipun Thapa / Computer Organization 22 https://genuinenotes.com

Conversion 5.Decimal to octal

6. Decimal to Hexadecimal

Example: convert (4768)10 to hex. = 4768 / 16 = 298 remainder 0 = 298 / 16 = 18 remainder 10 (A) = 18 / 16 = 1 remainder 2 = 1 / 16 = 0 remainder 1 Answer: 1 2 A 0

Example: convert (177)10 to octal 177 / 8 = 22 remainder is 1 22 / 8 = 2 remainder is 6 2 / 8 = 0 remainder is 2 Answer = (261)8

Nipun Thapa / Computer Organization 23 https://genuinenotes.com

Conversion 7.Binary to octal and Hex

Example − Convert binary number 10010110 into octal

number. First convert this into decimal number = (10010110)2 = 1x27+0x26+0x25+1x24+0x23+1x22+1x21+0x20 = 128+0+0+16+0+4+2+0 = (150)10 Then, convert it into octal number = (150)10 = 2x82+2x81+6x80 = (226)8 which is answer.

Nipun Thapa / Computer Organization 24 https://genuinenotes.com

Conversion 7.Binary to octal and Hex

Using Grouping

Nipun Thapa / Computer Organization 25

Octal Digit Value Binary Equivalent

0 000

1 001

2 010

3 011

4 100

5 101

6 110

7 111

https://genuinenotes.com

Conversion 7.Binary to octal

• So, if you make each group of 3 bit of binary input number, then replace each group of binary number from its equivalent octal digits. That will be octal number of given number . Note that you can add any number of 0’s in leftmost bit (or in most significant bit) for integer part and add any number of 0’s in rightmost bit (or in least significant bit) for fraction part for completing the group of 3 bit, this does not change value of input binary number.

• So, these are following steps to convert a binary number into octal number. • Take binary number • Divide the binary digits into groups of three (starting from right) for integer part

and start from left for fraction part. • Convert each group of three binary digits to one octal digit.

This is simple algorithm where you have to grouped binary number and replace their equivalent octal digit.

Nipun Thapa / Computer Organization 26 https://genuinenotes.com

Conversion 7.Binary to octal

Example-1 − Convert binary number 1010111100 into octal

number. Since there is no binary point here and no fractional part. So,

Nipun Thapa / Computer Organization 27 https://genuinenotes.com

Conversion 7.Binary to octal

Therefore, Binary to octal is. = (1010111100)2 = (001 010 111 100)2 = (1 2 7 4)8

= (1274)8

Nipun Thapa / Computer Organization 28 https://genuinenotes.com

Conversion 7.Binary to octal

Example-2 Convert binary number 0110 011.1011 into octal number. Since there is binary point here and fractional part. So,

Nipun Thapa / Computer Organization 29 https://genuinenotes.com

Conversion 7.Binary to octal

Therefore, Binary to octal is. = (0110 011.1011)2 = (0 110 011 . 101 1)2 = (110 011 . 101 100)2 = (6 3 . 5 4)8 = (63.54)8

Nipun Thapa / Computer Organization 30 https://genuinenotes.com

Conversion 8.Binary to Hexadecimal

These are following steps to convert a binary number into hexadecimal number.

• Take binary number • Divide the binary digits into groups of four (starting from

right) for integer part and start from left for fraction part. • Convert each group of four binary digits to one

hexadecimal digit.

Nipun Thapa / Computer Organization 31 https://genuinenotes.com

Conversion 8.Binary to Hexadecimal

Example-1 − Convert binary number 1010101101001 into hexadecimal number. Since there is no binary point here and no fractional part. So,

Nipun Thapa / Computer Organization 32 https://genuinenotes.com

Conversion 8.Binary to Hexadecimal

Example − Convert binary number 1101010 into hexadecimal number. First convert this into decimal number: = (1101010)2 = 1x26+1x25+0x24+1x23+0x22+1x21+0x20 = 64+32+0+8+0+2+0 = (106)10 Then, convert it into hexadecimal number = (106)10 = 6x161+10x160 = (6A)16 which is answer.

Nipun Thapa / Computer Organization 33 https://genuinenotes.com

Conversion 8.Binary to Hexadecimal

Nipun Thapa / Computer Organization 34

Hexa 0 1 2 3 4 5 6 7

Binary 0000 0001 0010 0011 0100 0101 0110 0111

Hexa 8 9 A=10 B=11 C=12 D=13 E=14 F=15

Binary 1000 1001 1010 1011 1100 1101 1110 1111

https://genuinenotes.com

Conversion 8.Binary to Hexadecimal

Therefore, Binary to hexadecimal is, = (1010101101001)2 = (1 0101 0110 1001)2 = (0001 0101 0110 1001)2 = (1 5 6 9)16 = (1569)16

Nipun Thapa / Computer Organization 35 https://genuinenotes.com

Conversion 8.Binary to Hexadecimal

Example-2 − Convert binary number 001100101.110111 into hexadecimal number. Since there is binary point here and fractional part. So,

Nipun Thapa / Computer Organization 36 https://genuinenotes.com

Conversion 8.Binary to Hexadecimal

Therefore, Binary to hexadecimal is, = (001100101.110111)2 = (0 0110 0101 . 1101 1100)2 = (0110 0101 . 1101 1100)2 = (6 5 . D C)16 = (65.DC)16

Nipun Thapa / Computer Organization 37 https://genuinenotes.com

Complements Complements are used in digital systems for simplifying the subtraction operation and for logic manipulation. Two types of complements are:

• r’s complement • (r-1)’s complement

Nipun Thapa / Computer Organization 38 https://genuinenotes.com

Complements Complements are used in digital systems for simplifying the subtraction operation and for logic manipulation. Two types of complements are:

• r’s complement • (r-1)’s complement

When the value of the base r is substituted in the name, the two types are referred to as the 2’ and 1’s complements for binary numbers and the 10’s and 9’s complements for decimal numbers.

Nipun Thapa / Computer Organization 39 https://genuinenotes.com

Complements i) r’s complement

r’s complement of N (positive number with base r) is defined as rn – N, for N ≠ 0 and 0, for N=0 where, n=number of digits (integer parts only) • E.g. (147.53)10, c = 103 – 147.53 = 852.47 Ans.

Nipun Thapa / Computer Organization 40 https://genuinenotes.com

Complements ii) (r-1)’s complement (r-1)’s complement of N (positive number with base

r) is defined as (rn – r - m) – N, for number with fraction (rn – 1) – N, for number with integer only where, n number of digits in integer part of N m number of digits in fraction part of N r base or radix E.g. (147.53)9, c = 103 – 10-2 - 147.53 = 852.46 Ans

Nipun Thapa / Computer Organization 41 https://genuinenotes.com

Complements • To find (r-1)’s complement, subtract all digit from (r-1). E.g. for 1’s complement, subtract each digit from 1. for 7’s complement, subtract each digit from 7. for 9’s complement, subtract each digit from 9. for 15’s complement, subtract each digit from 15. And, • To find r’s complement, subtract each digit from (r-1), and then add 1 to the last digit. E.g. for 2’s complement, subtract each digit from 1, and then add 1 to the last digit. for 8’s complement, subtract each digit from 7, and then add 1 to the last digit. for 10’s complement, subtract each digit from 9, and then add 1 to the last digit for 16’s complement, subtract each digit from 15, and then add 1 to the last digit. • C/W, Give some examples on 1’s complement and 2’s complement.

Nipun Thapa / Computer Organization 42 https://genuinenotes.com

Complements For eg : 9’s complement of 54670 with n= 5 we have 106 = 1000000 and 106-1=999999 then, 999999-546700=453299 and the 9’s complement of 12389 is

9999-12389=87610 For binary number r=2 and r-1 = 1, so the 1’s complement of N is (2n – 1) – N . If , n = 4 , we have 24= (10000)2 – 1 = (1111)2 The (r-1)’s complement of octal or hex number are obtained by

subtracting each digit from 7 or F(decimal 15) respectively .

Nipun Thapa / Computer Organization 43 https://genuinenotes.com

Complements r ‘ s Complement of an n-digit Note : the r’s complement is obtained by adding 1 to the (r-1)’s complements ie: Rn-N = [ ( rn-1 ) - N ] +1 i) Thus 10’s complement of decimal 2389 is

7610+1=7611

Nipun Thapa / Computer Organization 44 https://genuinenotes.com

Subtracting of Unsigned Number #Subtraction with r’s complement • Subtraction of two positive numbers (M - N), both of base r, is

done as follows: i) Add M to r’s complement of N. ii) If an end carry occurs, discard it. What is left is result. iii) If an end carry does not occur, take r’s complement of the number obtained in step (i) and place a negative sign in front. That is the result.

#Subtraction with (r-1)’s complement • Subtraction of two positive numbers (M - N), both of base r, is

done as follows: i) Add M to (r-1)’s complement of N. ii) If an end carry occurs, add 1 to LSB. What is received is result. iii) If an end carry does not occur, take (r-1)’s complement of the number obtained in step (i) and place a negative sign in front. That is the result.

Nipun Thapa / Computer Organization 45 https://genuinenotes.com

Subtracting of Unsigned Number •

Nipun Thapa / Computer Organization 46 https://genuinenotes.com

Subtracting of Unsigned Number •

Nipun Thapa / Computer Organization 47 https://genuinenotes.com

Subtracting of Unsigned Number Using the two binary numbers X=1010100 and Y=1000011, we perform the subtraction X-Y and Y-X using 2’s complements : X = 1010100 2’s complement of Y = +0111101 Sum = 10010001 Discard end carry 27 = -10000000 Answer : X-Y = 0010001 Y = +000011 2’s complement of X = +0101100 Sum = 1101111 There is no end carry Answer is negative 0010001 = 2’s complement of 1101111

Nipun Thapa / Computer Organization 48 https://genuinenotes.com

Fixed-Point Representation

• Because of hardware limitations, computers must represent everything with 1's and 0's, including the sign of a number.

• There will be problem in storing +ve/-ve sign (+/-) and binary (or decimal) point.

• Convention is 0 for +ve sign and 1 for –ve sign.

Nipun Thapa / Computer Organization 49 https://genuinenotes.com

Fixed-Point Representation Integer Representation

Suppose, we have 8-bit register. For +ve number,

i) Signed-magnitude representation When an integer binary number is positive, the sign is represented by 0 and the magnitude by a positive binary number.

E.g. +14 = 0 0001110

For –ve number,

i) Signed-magnitude representation 1 for the -ve sign followed by binary equivalent of that number. E.g. -14 = 1 0001110 ii) Signed-1’s complement representation 1 for the -ve sign followed by 1’s complement of that number. E.g. -14 = 1 1110001 iii) Signed-2’s complement representation 1 for the -ve sign followed by 2’s complement of that number. E.g. -14 = 1 1110010

Nipun Thapa / Computer Organization 50 https://genuinenotes.com

Fixed-Point Representation • Signed-magnitude system is used in ordinary arithmetic

while the signed-complement is used in computer arithmetic.

• The 1’s complement has two representations of 0 (+0 and -0), hence brings difficulties and used in some older computers.

• The 2’s complement is widely used.

Nipun Thapa / Computer Organization 51 https://genuinenotes.com

Fixed-Point Representation Arithmetic Addition

Note: negative number must initially be in 2’s complement

and that if the sum obtained after the addition is negative, it is in 2’s complement form. e.g.

Nipun Thapa / Computer Organization 52

+6 : 0 0000110 +13 : 0 0001101 +19 : 0 0010011

- 6 : 1 1111010 +13 : 0 0001101 +7 : 0 0010011

+6 : 0 0000110 - 13 : 1 1110011 - 7 : 1 1111001

-6 : 1 1111010 -13 : 1 1110011 -19 : 1 1101101

https://genuinenotes.com

Fixed-Point Representation Overflow

• When two numbers of n digits each are added and the sum occupies n + 1 digits, we say that an overflow occurred.

• An overflow is a problem in digital computers because the width of registers is finite.

• A result that contains n + 1 bits cannot be accommodated in a register with a standard length of n bits.

• For this reason, many computers detect the occurrence of an overflow, and when it occurs, a corresponding flip-flop is set which can then be checked by the user.

• The detection of an overflow after the addition of two binary numbers depends on whether the numbers are considered to be signed or unsigned.

Nipun Thapa / Computer Organization 53 https://genuinenotes.com

Fixed-Point Representation Overflow

• When two unsigned numbers are added, an overflow is detected from the end carry out of the most significant position.

• In the case of signed numbers, the leftmost bit always represents the sign, and negative numbers are in 2's complement form. When two signed numbers are added, the sign bit is treated as part of the number and the end carry does not indicate an overflow.

• An overflow cannot occur after an addition if one number is positive and the other is negative, since adding a positive number to a negative number produces a result that is smaller than the larger of the two original numbers.

Nipun Thapa / Computer Organization 54 https://genuinenotes.com

Fixed-Point Representation Overflow

• An overflow may occur if the two numbers added are both either positive or both negative.

• E.g.

• An overflow condition can be detected by observing that if these two carries are not equal, an overflow condition is produced.

• If the two carries are applied to an exclusive OR (XOR) gate, an overflow will be detected when the output of the gate is equal to 1.

Nipun Thapa / Computer Organization 55 https://genuinenotes.com

Floating-Point Representation Floating-Point Representation has two parts: i) Mantissa (a signed number, may be a fraction or an integer) ii) Exponent

E.g. +62345.54 = +(0.6234554)*10+5

Nipun Thapa / Computer Organization 56

Fraction Exponent +0.6234554 +5

https://genuinenotes.com

Floating-Point Representation • General form,

• m * re, where r = radix • A floating point binary number is represented in a similar

manner except that it uses base 2 for the exponent. For example, the binary number +1001.11 is represented with an 8-bit fraction and 6-bit exponent as follows: • m * 2e = +(.100111)2 * 2+4

• The fraction has a 0 in the leftmost position to denote positive. • The binary point of the fraction follows the sign bit but is not

shown in the register. • A floating point number is said to be normalized if the most

significant digit of the mantissa is nonzero.

Nipun Thapa / Computer Organization 57

Fraction Exponent 01001110 000100

https://genuinenotes.com

Floating-Point Representation Two main standard forms of the floating point number by

• ANSI (American National Standards Institute) • IEEE (Institute of Electrical and Electronic Engineers)

The ANSI 32-bit floating-point number in byte format is:

Nipun Thapa / Computer Organization 58

where, S = sign of Mantissa E = exponent bits (in 2’s complement) M = mantissa bits

E.g. 13 = 1101 = +(.1101) * 24 = 00000100 11010000 00000000 00000000 -17 = -10001 = -(.10001) * 25 = 10000101 10001000 00000000 00000000 -0.12510 = -0.0012 = -(.1) * 2-2 = 11111110 10000000 00000000 00000000

https://genuinenotes.com

Thank You

Chapter 1 is finished !!!

Nipun Thapa / Computer Organization 59 https://genuinenotes.com