1 / 74

DATA REPRESENTATION

DATA REPRESENTATION. Digital computers store information in binary Binary allows two states * On yes true 1 * Off no false 0 Each digit in a binary number is called a bit 0 1 1 0 bit 0ff 0n 0n 0ff

Download Presentation

DATA REPRESENTATION

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DATA REPRESENTATION Digital computers store information in binary Binary allows two states * On yes true 1 * Off no false 0 Each digit in a binary number is called a bit 0 1 1 0 bit 0ff 0n 0n 0ff Binary number system == how numbers can be processed in binary IT221

  2. Binary Numbers • Digits are 1 and 0 1 = true 0 = false • MSB – most significant bit • LSB – least significant bit • Bit numbering: IT221

  3. Number system • A number system of base (radix) r is a system that uses distinct symbol for r digits. • Numbers are represented by a string of digit symbols. IT221

  4. Number system • The base of a number is usually specified as a subscript, e.g.: • (01000011)2, • (71203)8, • (FF078ABC)16, ...etc. • Or a letter indicating the base (d for decimal, b for binary, o for octal and h for hexadecimal) is appended to the number, e.g.: • 01000011b, • 71203o, • FF078ABCh, ...etc. IT221

  5. Number system IT221

  6. Number system • The value of a digit depends not only on its value but also on its position within the number → gives the power of the radix by which it is multiplied. IT221

  7. Positional values in the decimal number system IT221

  8. Positional values in the binary number system IT221

  9. Example 2 10 -1 -2 • 379.25= 3*10 + 7*10 + 9*10+2*10+5*10 n n-1 • (dndn-1...d0.f1f2…fm)r = dn* ( r ) + dn-1* ( r ) +….+ 0 -1 -2 -m d0* ( r ) + f1* ( r ) + f2* ( r ) +…+ fm* ( r ) Converting to decimal IT221

  10. Examples on converting from different bases to Decimal Convert the following to Decimal: • (1001001)2 • (203)8 • (FA07)16 Solution: • (1001001)2 = 1 + 0*21 + 0*22 + 1*23 + 0*24 + 0*25 + 1*26 = 73d • (203)8 = 3 + 0*81 + 2*82 = 131d • (FA07)16 = 7 + 0*161 + 10*162 + 15*163 = 64007d IT221

  11. Conversion from decimal • The conversion of a decimal integer into a base r is done by: • Whole numbers: divisions by r • Fractions: repeated multiplication by r. IT221

  12. Conversion from decimal To convert from decimal to any numbering system with base r : • The decimal number is divided by r, • Keeping the remainder aside, the result is further divided by r, and the new remainder is kept aside, • The new result is divided again by r, and so on till the result is less than r and this would be the last remainder, • The remainders make up the equivalent base-r number, with the last remainder being the most-significant digit and the first remainder being the least-significant digit. IT221

  13. Conversion to binaryWhole number • Ex.: (67)10 = (?)2 2 67 2 33 rem 1 LSB 2 16 rem 1 2 8 rem 0 2 4 rem 0 67d= 10000112 2 2 rem 0 2 1 rem 0 0 rem 1 MSB IT221

  14. Fraction Repeat multiplication by 2 until the fractional product is 0 Ex.: (0.3125)10 = (?)2 Carry 0.3125* 2 = 0.625 0 MSB 0.625* 2 = 1.25 1 (0.3125)10= (0.0101)2 0.25* 2 = 0.5 0 0.5* 2 = 1.00 1 LSB IT221

  15. Conversion to base r (50) 10 = (?)8 8 50 8 6 2 0 6 (50)10 = (62)8 IT221

  16. Octal and Hexadecimal number systems • Binary numbers are long. • On average, it takes about 3.3 times as many digits to represent a value in binary as it does to represent the same value in decimal. IT221

  17. Octal and Hexadecimal number systems If a base R1 is an integral power of d another base R2 i.e. R1= R2 → Group of d digits in base R2 maps directly into one digit in base R1 And each digit in base R1 maps directly into d digits in base R2. IT221

  18. Octal number systems 3 Base = 8 = 2 → d = 3 Digits: 0 → 7 Binary to Octal conversion: Group every 3 bits (starting from the right) Replace them by their corresponding octal digit Ex.: ( 0 1 0 1 1 0 1 0 1 )2 = ( 265 )8 ( 1 0 0 0 1 )2 = ( 21 )8 IT221

  19. Octal to binary conversion • Replace each digit by its 3-bit binary equivalent. • Ex.: (476)8 = (100111110)2 IT221

  20. Octal to binary conversion IT221

  21. Binary – Octal conversion table BinaryOctalBinaryOctal 000 0 001000 10 001 1 010000 20 010 2 011 3 100 4 101 5 110 6 111 7 IT221

  22. Hexadecimal number systems (Hex) 4 Base = 16 = 2 → d = 4 Digits: 0,1,2,…..,9,A,B,C,D,E,F Where A = 10, B = 11, C = 12, D = 13, E = 14, F = 15 IT221

  23. Binary to Hex conversion Group each 4 bits and replace them by their corresponding hex digit. Ex.: (1 0 1 1 0 1 0 1 )2 = ( B5 )16 IT221

  24. Hex to binary conversion Replace each digit by their 4 bit binary equivalent Ex.: ( 1D9C )16 = (0001110110011100 )2 IT221

  25. Hex to binary conversion IT221

  26. Binary – Hexadecimal conversion table BinaryHexBinaryHex 0000 0 1000 8 0001 1 1001 9 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101 D 0110 6 1110 E 0111 7 1111 F (00010100)2 → (14)16 → ( 20 )10 (12.8)16 →(00010010.1000)2 → (18.5)10 IT221

  27. Binary Arithmetic operations • Addition 0+0 = 0 0+1 = 1 1+0 = 1 1+1 = 10 (carry) IT221

  28. Binary Arithmetic operations • Subtraction 0 - 0 = 0 0 - 1 = 1 (after borrowing) 1 - 0 = 1 1 - 1 = 0 IT221

  29. Binary Arithmetic operations • Multiplication 0*0 = 0 0*1 = 0 1*0 = 0 1*1 = 1 IT221

  30. ADDITION • Like decimal numbers, two numbers can be added by adding each pair of digits together with carry propagation. IT221

  31. Example Carries IT221

  32. SUBTRACTION • Two numbers can be subtracted by subtracting each pair of digits together with borrowing, where needed. IT221

  33. SUBTRACTION IT221

  34. Representation of signed binary numbers • Given a fixed number of bit positions (n), we n can represent 2 patterns: From (00..0)2 to (11..1)2. • Using unsigned numbers we can represent n 0 → 2 -1 n • Using signed numbers → 2 positive & negative patterns IT221

  35. Complementary notations • The most commonly used way of representing signed numbers. It greatly simplifies all arithmetic operations. • Positive number is represented as it is (like an unsigned positive number). • Negative numbers are represented by the complement of unsigned number. IT221

  36. Complementary notations • The value used for complementation is a power of the base or less one than a power of the base. • For binary numbers: we have 2’s complement and 1’s complement. • For decimals, we have 10’s complement and 9’s complement. • For hex. Numbers we have 16’s complement and F’s (15’s) complement. IT221

  37. One’s complement • Is obtained by subtracting the number from (11..1)2 (n 1’s) → reversing each bit: changing every 1 to 0 and every 0 to 1. • Ex.: represent +(14d), -(14d) in 8-bit binary number • (+14)10 = ( 00001110)2 = (00001110)1s • (-14)10 = -( 00001110)2 = (11110001)1s IT221

  38. For 8-bits number system: • Largest positive number: 0 1111111 = +(127)10 • smallest negative number: 1 0000000 = - (127)10 • Zeroes: 0 0000000 1 1111111 • Range: m-1 m-1 - (2 -1) to + 2 -1 (m : the number of bits) • -(127)10 to +(127)10 • The most significant bit represents the sign: 0 = +ve ; 1 = -ve. IT221

  39. 2’s complement • Take the 1’s complement and add 1 → invert all the bits and add 1. • Ex.: 2’s complement of (01110100)2: 1’s complement = (10001011)2 add 1 → 2’s complement = (10001100)2 IT221

  40. 2’s complement • 2’s complement of (00000000)2: 1’s complement = (11111111)2 add 1 → (100000000)2 • 2’s complement of n-bit number include only the rightmost n bits: 2’s complement of (00000000)2 = (00000000)2 IT221

  41. 2’s complement - For 8-bit binary numbers 2’s complement of (5)d = (00000101)2: 1’s complement = (11111010)2 add 1→ (11111011)2 510 + (-5)10 → 000001012 + 111110112 = 1000000002 Carry 2’s complement of any N integer represents –N: N + (-N) = 0 IT221

  42. 2’s complement • To find the 2’s complement of a binary number, proceeding from right to left, leave all bits unchanged up to and including the first `1`. Reverse all the remaining bits. • Range of signed value that can be represented in 2’s complemented notation is m-1 m-1 - 2 to 2 -1 IT221

  43. For 8-bits number system: • Largest positive number: 0 1111111 = +(127)10 • smallest negative number: 1 0000000 = - (128)10 • Zero: 0 0000000 • Range: -(128)10 to +(127)10 • The most significant bit represents the sign: • 0 = +ve ; 1 = -ve. IT221

  44. 2’s complement in hexadecimal • Each group of four bits corresponds to a single hexadecimal digit. • Subtract each hexadecimal digit from F and then add 1 (equivalent of taking the 16’s complement). IT221

  45. Ex.: 2’s complement of (3A6E)16 1’s complement: FFFF - 3A6E C591 + 1 2’s complement: (C592)16 IT221

  46. Comparing 2’s complement numbers Check the signs: If they differ, they determine the order If they are the same, the order of the numbers is the same as that of their representations. IT221

  47. Ex.: (01001100)2 and (10100101)2 Different signs → the 1st # is +ve the 2nd # is –ve → 1st # > 2nd # IT221

  48. (10110010)2 and (10111001)2 • Both numbers are negative: 1st # < 2nd # IT221

  49. Signed binary arithmetic Overflow • Signed binary numbers are of a fixed range. • If the result of addition/subtraction goes beyond this range, overflow occurs. • Two conditions under which overflow can occur are: (i) positive add positive gives negative (ii) negative add negative gives positive IT221

  50. 2s complement addition Algorithm: • Perform binary addition on the two numbers. • Ignore the carry out of the MSB. • Check for overflow: Overflow occurs if the carriers into and out of the MSB are different. IT221

More Related