Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Representation Dr. Ahmed El-Bialy Dr. Sahar Fawzy.

Similar presentations


Presentation on theme: "Data Representation Dr. Ahmed El-Bialy Dr. Sahar Fawzy."— Presentation transcript:

1 Data Representation Dr. Ahmed El-Bialy Dr. Sahar Fawzy

2 Data Representation To process data by brain, it must be converted to an appropriate internal format. To process data by brain, it must be converted to an appropriate internal format. To process data by Computers, it must be converted to an appropriate internal formats To process data by Computers, it must be converted to an appropriate internal formats So how various types of data are stored internally in hardware ?

3 Data Data are defined by: Data are defined by: Set of ValuesSet of Values Set of operations on these values.Set of operations on these values. Text Characters Concatenation String Comparison Numeric Numbers Vectors-Matrices Add- Sub- Multi … Instructions Machine Operations

4 Numeric Data Real UnsignedSigned Integers Floating Point Decimal Binary Octal Hexadecimal Signed bit 1’s Comp 2’s Comp Fixed Point

5 Concept of Number System The Decimal (1346) 10 (base 10) is: The Decimal (1346) 10 (base 10) is: 1 x 1000 1000 1 x 10 3 + 3 x 100 300 3 x 10 2 + 4 x 10 40 4 x 10 1 + 6 x 1 6 6 x 10 0 = 1346 The number (1011) 2 (base 2) is: The number (1011) 2 (base 2) is: 1 x 8 8 1 x 2 3 +0 x 4 0 0 x 2 2 +1 x 2 2 1 x 2 1 +1 x 1 1 1 x 2 0 = (13) 10 Unsigned Integers

6 Data Conversions The “radix” (base) “r” The “radix” (base) “r” To convert from any type to decimal you multiply each digit by the base-power number: To convert from any type to decimal you multiply each digit by the base-power number: e.g.: Octal (r=8) (163) 8 e.g.: Octal (r=8) (163) 8 +6x8 1 3x8 0 3x8 0 +1x8 2 =(115) 10

7 Data Conversions e.g.: To convert from Binary to decimal you multiply each digit by the base-power (r=2) : (110110) 2 e.g.: To convert from Binary to decimal you multiply each digit by the base-power (r=2) : (110110) 2 +1x2 4 +0x2 3 +1x2 5 =(54) 10 +1x2 1 0x2 0 0x2 0 +1x2 2

8 Data Conversions e.g.: To convert from Hex to decimal you multiply each digit by the base-power (r=16) : (C13FA2) 16 e.g.: To convert from Hex to decimal you multiply each digit by the base-power (r=16) : (C13FA2) 16 +1x16 4 +3x16 3 +Cx16 5 =( 12664738 ) 10 +Ax16 1 2x16 0 2x16 0 +Fx16 2

9 From any System to Decimal Hexadecimal Decimal Octal Binary x 8 n x 16 n x 2 n

10 Conversion of Decimal to Binary Repeat dividing of the decimal number by 2 and keep the remainder until you get a 0 quotient: Repeat dividing of the decimal number by 2 and keep the remainder until you get a 0 quotient: e.g.: Convert (125) 10 to binary e.g.: Convert (125) 10 to binary 2 | 125 2 | 62+1 2 | 31+0 2 | 15+1 2 | 7+1 2 | 3+1 2 | 1+1 0+1 0+1  (125) 10 = (1111101) 2  (125) 10 = (1111101) 2

11 Conversion of Decimal to Octal Repeat dividing of the decimal number by 8 and keep the remainder until you get a 0 quotient: Repeat dividing of the decimal number by 8 and keep the remainder until you get a 0 quotient: e.g.: Convert (125) 10 to Octal e.g.: Convert (125) 10 to Octal 8 | 125 8 | 15+5 8 | 1+7 0+1 0+1  (125) 10 = (175) 8  (125) 10 = (175) 8

12 Conversion of Decimal to Hex Repeat dividing of the decimal number by 16 and keep the remainder until you get a 0 quotient: Repeat dividing of the decimal number by 16 and keep the remainder until you get a 0 quotient: e.g.: Convert (73462) 10 to binary e.g.: Convert (73462) 10 to binary 16 | 73462 16 | 4591 +6 16 | 286 + 15  F 16 | 17+ 14  E 16 | 1+1 0+1 0+1 -> (73462) 10 = (11EF6) 16 -> (73462) 10 = (11EF6) 16

13 Conversion Hexadecimal Decimal Octal Binary x 8 n x 16 n x 2 n ÷ 16 ÷ 8 ÷ 2

14 DecBin Octal Hex 0000 1111 21022 31133 410044 510155 611066 711177 81000108 91001119 10101012A 11101113B 12110014C 13110115D 14111016E 15111117F DecBin Octal Hex 16100002010 16100002010 17100012111 18100102212 19100112313 20101002414 21101012515 22101102616 23101112717 24110003018 25110013119 2611010321A 2711011331B 2811100341C 2911101351D 3011110361E 3111111371F Concept of Number System

15 Conversion from Binary to Octal Conversion between octal and binary is trivial. Since 2 3 = 8, every 3 binary digits converts to 1 octal digit: Conversion between octal and binary is trivial. Since 2 3 = 8, every 3 binary digits converts to 1 octal digit: The conversion is Binary Octal Binary Octal 0000 0011 0102 0113 1004 1015 1106 1117

16 Conversion from Binary to Octal Starting at the RIGHT, block the binary number into groups of 3 bits: Starting at the RIGHT, block the binary number into groups of 3 bits: e.g.: (11011101101110) 2 e.g.: (11011101101110) 2 (011|011|101|101|110) 2 = (33556) 8 = (33556) 8

17 Conversion from Octal to Binary Conversion from octal to binary is even easier. Conversion from octal to binary is even easier. e.g.: Convert (60125) 8 to binary e.g.: Convert (60125) 8 to binary 110|000|001|010|101 Then remove the dividing bars (60125) 8 =(110000001010101) 2

18 Conversion from Binary to Hex Starting at the RIGHT, block the binary number into groups of 4 bits: Starting at the RIGHT, block the binary number into groups of 4 bits: e.g.: (11011101101110) 2 e.g.: (11011101101110) 2 (0011|0111|0110|1110) 2 = (376E) 16 = (376E) 16

19 Conversion from Hex to Binary Conversion from Hex to binary is easy. Conversion from Hex to binary is easy. e.g.: Convert (3F56E) 16 to binary e.g.: Convert (3F56E) 16 to binary 0011|1111|0101|0110|1110 Then remove the dividing bars (3F56E) 16 =(111111010101101110) 2

20 Representing Signed Integers The number system we studied represent positive numbers The number system we studied represent positive numbers In decimal, we have positive and negative numbers. In decimal, we have positive and negative numbers. We should also take into consideration that the number of bits in a binary number is fixed by the hardware design (the machine's word length). We should also take into consideration that the number of bits in a binary number is fixed by the hardware design (the machine's word length).

21 Representing Signed Integers There are actually three possible schemes for representing signed numbers. There are actually three possible schemes for representing signed numbers. All agree on using the leftmost bit in the number to encode the sign All agree on using the leftmost bit in the number to encode the sign with 0 encoding +with 0 encoding + and 1 encoding -.and 1 encoding -. 1. Sign magnitude 1. Sign magnitude 2. One's complement 2. One's complement 3. Two's complement 3. Two's complement

22 Sign-Magnitude The simplest way to represent negative numbers is called sign-magnitude. The simplest way to represent negative numbers is called sign-magnitude. It is based on the method we use with decimal numbers: It is based on the method we use with decimal numbers: To represent a positive number in (say) 8 bits, represent its magnitude as seven bits and prefix a 0.To represent a positive number in (say) 8 bits, represent its magnitude as seven bits and prefix a 0. To represent a negative number in (say) 8 bits, represent its magnitude as seven bits and prefix a 1.To represent a negative number in (say) 8 bits, represent its magnitude as seven bits and prefix a 1. Example: +65  01000001 Example: +65  01000001 Example: - 65  11000001 Example: - 65  11000001

23 1's complement a better method is called 1's complement. In 1's complement, we proceed as follows: a better method is called 1's complement. In 1's complement, we proceed as follows: To represent a positive number in (say) 8 bits, represent it as an unsigned number using seven bits and prefix a 0.To represent a positive number in (say) 8 bits, represent it as an unsigned number using seven bits and prefix a 0. To represent a negative number in 8 bits, represent its absolute value as above, then invert all the bits (which results in a left most bit of 1)To represent a negative number in 8 bits, represent its absolute value as above, then invert all the bits (which results in a left most bit of 1) Example: +65  01000001 Example: +65  01000001 1’s complement : - 65  10111110 1’s complement : - 65  10111110

24 Two's complement In 2’s complement, add 1 to the 1’s complement in case of a negative number In 2’s complement, add 1 to the 1’s complement in case of a negative number Example: +65  01000001Example: +65  01000001 1’s complement: - 65  101111101’s complement: - 65  10111110 2’s complement : - 65  101111112’s complement : - 65  10111111

25 Addition in Binary Example: Example: 01011010 90 01101100 + 108 ----------- ---- 11000110 198 Example: Example: 00111001 57 01011010 + 90 -------- 10010011 147

26 Subtraction in Binary 2’Complement Examples: Examples: 00001000 8 11111111 -1 -------- -- 00000111 7 Examples: Examples: 11111110 -2 -------- -- 11111100 -4 Examples: Examples: 11000001 -63 01000000 64 -------- -- 00000001 1 1 carry out of sign position discarded

27 Real Numbers Fixed point: 234.567 Fixed point: 234.567 11234.56 11234.56 0.00034567 0.00034567 Floating point: 2.34567 * 10 2 Floating point: 2.34567 * 10 2 1.123456 * 10 4 1.123456 * 10 4 3.4567 * 10 -4 3.4567 * 10 -4

28 Real Numbers (2) A real number is stored internally as a mantissa times a power of some radix A real number is stored internally as a mantissa times a power of some radix m * r e r = 2 ( for binary) r = 2 ( for binary) m  mantissa m  mantissa

29 Conversion of Fraction Decimal to Binary Repeat multiplying of the decimal number by 2 and keep the units : Repeat multiplying of the decimal number by 2 and keep the units : e.g.: Convert (.40625 ) 10 to binary e.g.: Convert (.40625 ) 10 to binary 0.40625 x 2 = 0.8125 units 0 0.8125 x 2 = 1.625 units 1 0.625 x 2 = 1.25 unit2 1 0.25 x 2 = 0.5 unit2 0 0.5 x 2 = 1.0 unit2 1 0.0 0.0 (0.40625) 10 = (0.01101) 2

30 IEEE Format IEEE has developed a floating point standard (Standard 754) IEEE has developed a floating point standard (Standard 754) The standard provides two different formats for single and double precision numbers. The standard provides two different formats for single and double precision numbers. We will consider the single precision representation as an example. We will consider the single precision representation as an example. 31302322 S 0 expmantissa

31 IEEE Format s = sign of mantissa: 0 == +, 1 == - s = sign of mantissa: 0 == +, 1 == - exp = exponent as power of 2, stored in excess 127 form - i.e. value stored is 127 + true value. exp = exponent as power of 2, stored in excess 127 form - i.e. value stored is 127 + true value. ex: true exponent = 0; stored exponent = 127ex: true exponent = 0; stored exponent = 127 ex: true exponent = 127; stored exponent = 254ex: true exponent = 127; stored exponent = 254 ex: true exponent = -126; stored exponent = 1ex: true exponent = -126; stored exponent = 1 31302322 S 0 expmantissa fraction

32 IEEE Format The significand (magnitude of mantissa) is normalized to lie in the range 1.0 <= |m| < 2.0. This implies that the leftmost bit is always 1, but need not be stored. The significand (magnitude of mantissa) is normalized to lie in the range 1.0 <= |m| < 2.0. This implies that the leftmost bit is always 1, but need not be stored. The 23 bits allocated are used to store the bits to the right of the binary point. The 23 bits allocated are used to store the bits to the right of the binary point. The missing leftmost bit “1” is inserted to the left of the binary point by the hardware when doing arithmetic. (This is called hidden-bit normalization, and is why this field is labeled "fraction".) The missing leftmost bit “1” is inserted to the left of the binary point by the hardware when doing arithmetic. (This is called hidden-bit normalization, and is why this field is labeled "fraction".)

33 IEEE Format e.g.: e.g.: (-5.375) 10  (-101.011 ) 2  (-1.01011 x 2 2 ) 2 Sign bit =1 (negative) Sign bit =1 (negative) exp = 2 + 127 = 129 = (10000001) 2 exp = 2 + 127 = 129 = (10000001) 2 Significand= 1.01011 Significand= 1.01011 Fraction = 01011 Fraction = 01011 IEEE format: IEEE format: 1 10000001 01011000000000000000000 1 10000001 01011000000000000000000

34 Other Binary Codes Binary Coded Decimal Binary Coded Decimal Gray Code Gray Code

35 Error Detection Codes Parity Codes Parity Codes Odd / evenOdd / even GeneratorGenerator CheckerChecker

36 Text Computers deals only with numbers Computers deals only with numbers Therefore, text is coded into numbers. Therefore, text is coded into numbers. There are a variety of character codes in use on various systems, all of which begin by mapping the character set to a set of small unsigned integers, which are then in turn stored in binary form. There are a variety of character codes in use on various systems, all of which begin by mapping the character set to a set of small unsigned integers, which are then in turn stored in binary form.

37 Text ASCII (American Standard Code for Information Interchange): is the most widely used today. ASCII (American Standard Code for Information Interchange): is the most widely used today.

38 Thank you see you in the Logic Circuit and Boolean Algebra


Download ppt "Data Representation Dr. Ahmed El-Bialy Dr. Sahar Fawzy."

Similar presentations


Ads by Google