Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Representation of Information

Similar presentations


Presentation on theme: "Computer Representation of Information"— Presentation transcript:

1 Computer Representation of Information
Time: 90 min.

2 Outline Representation of Characters
Mathematical operations on numbers (addition) Signed integer representation Sign-magnitude notation Two’s complement notation Binary Notations Exercises Real Numbers Representation We will cover …. CSCE 106

3 Representation of Characters
A unique binary pattern/value is used to represent each of the printable characters on your keyboard (e.g. A, a, 4, *, [,’, etc. …), as well as the special control/unprintable characters (e.g. carriage return, line feed, tab, space, etc. …). A byte (8 bits) gives you the opportunity to have 28 (256) unique representations/patterns/values. There are standard character coding schemes to ease interchange of information, e.g. ASCII. The code is designed in such a way not only to preserve uniqueness, but also to keep the order which is often needed in manipulating characters/text, e.g. sorting. The value/pattern used to represent “A” is less by one than the value used to represent “B”, … etc. ASCII (American Standard Code for Information Interchange). CSCE 106

4 Right-hand Left-hand digit digit 3 4 5 6 7 1 2 8 9
P p 1 A Q a q 2 B R b r C S c s D T d t E U e u F V f v G W g w 8 H X h x 9 I Y i y J Z j z K k L l M m N n O o The slide gives some ASCII character representations in hexadecimal. Appendix A of your book gives the complete ASCII table in decimal. Each base 16 digit corresponds to 4 binary digits. CSCE 106

5 Mathematical Operations on Numbers (Addition)
Most of the mathematical operations on numbers from different number systems are conceptually identical to the decimal arithmetic you are used to. To add two numbers you do the following: Start at the rightmost digit. While there are more digits: Add the current digit of each operand. If the sum is less than the base/radix then record that sum, otherwise record the difference between the sum and the base/radix, and add one to the next digit of operand 1. The slide gives an algorithm for the process of addition. CSCE 106

6 Mathematical Operations on Numbers (Addition) (cont’d)
Decimal numbers: 1610 + 1510 ------ 3110 Start by adding The sum (11) is not less than the base (10), so (11-10) record 1, and carry 1 by adding it to the first digit of 16, giving 2, then add the next digit from each operand (2+1) to give 3. Octal numbers: 168 + 158 338 Start by adding The sum (1110) is not less than the base (8), so (11-8) record 3, and carry 1 by adding it to the first digit of 16, giving 2, then add the next digit from each operand (2+1) to give 3. The above discussions can be generalized to any base. CSCE 106

7 Signed Integers So far, we were representing unsigned integers in binary. We need to have a way for representing the sign of the number (positive or negative). We need to have a sign bit, or figure out some other way, so as to be able to represent negative values as well as positive ones. We will study two notations for representing signed integers: sign-magnitude notation, and two’s complement notation. How can we represent the negative integers in binary? CSCE 106

8 Sign-Magnitude Notation
It leaves the left most bit for the sign (sign bit), and uses the rest of the bits (m - 1) to represent the integer. 0 in the sign bit is used to represent positive values, and 1 is used to represent negative values. Therefore, the range of integer values i which can be represented with m bits is: -(2m-1 – 1) <= i <= +(2m-1 – 1) Using the sign–magnitude notation (in a byte): +2910 is represented as -2910 is represented as CSCE 106

9 Problems with Sign-Magnitude Notation
You might find this technique simple, natural, and straight forward, as it closely resembles the way you are used to writing numbers. However this notation creates mainly two problems for the computers: 0 representation ( is not ). Addition of mixed sign numbers ( (–510) and doesn’t result in –4). Thus the sign-magnitude notation is not used in computers. You can easily understand that 0 and -0 are the same, but the computer would need additional circuitry to figure this out. The straightforward addition algorithm of mixed sign numbers yields an incorrect result. Addition of a positive and a negative number must be treated as a subtraction problem, and this would need additional logic for the computer to check the sign bits before performing arithmetic. CSCE 106

10 Two’s Complement Notation
Two’s complement of an m-bit number N = (Bitwise/one’s complement of N) + 1 Examples of 8-bit numbers and their 2’s complement representation: +1 = –1 = = +29 = –29 = = (2’s complement of = = (29)) It is the notation used in computers to represent negative numbers. Notice that we still have the sign bit to indicate whether the number is a positive or negative one. You can never read a negative number represented using 2’s complement unless you get its 2’s complement to be able to transform it to decimal unsigned integer. CSCE 106

11 Two’s Complement Notation (cont’d)
For an m-bit signed integer in two’s complement notation, the range of integer values is from –2m–1 to 2m–1 – 1. When m = 8, the range is from –128 to 127. When m = 16, the range is from – to Two’s complement notation overcomes the problems of sign-magnitude notation. We have only one representation for the 0. Addition of mixed sign integers give correct results (with no need for extra logic). If you add -1 to 1 in two’s complement notation (in 8 bits) you will get 0: The rightmost 1 is an overflow, as we use only 8 bits to represent our number, and it is lost. Addition of mixed sign integers are performed in exactly the same way without the need of extra special computer hardware. Adding -5 to +1: (-4 in two’s complement) There are other representations for integers, e.g. BCD (binary coded decimal) system, that we will not study in this course. CSCE 106

12 Binary Notations Exercises
Representations of integers in a byte (8 bits) using different binary notations: Integer Unsigned Sign-magnitude 2's-complement   Not Possible Not Possible Not Possible Not Possible Not Possible Not Possible CSCE 106

13 Exercises (cont’d) Add (-37) to (25) using 8-bit two’s complement representation. Ans: 2510 -3710 ------ -1210  Carry + + Remember that you can always check that your answer is correct. CSCE 106

14 Exercises (cont’d) Subtract (39) from (-17) using 8-bit two’s complement representation. Ans: -1710 3910 ------ -5610  Carry Final carry overflows 8 bits. - + CSCE 106

15 Real Numbers Representation
Real or Floating-Point Numbers, e.g In binary 101 100 10-1 10-2 10-3 2 . 6 5 decimal point 24 23 22 21 20 2-1 2-2 2-3 1 . binary point CSCE 106

16 Real Numbers Representation (cont’d)
exponent Scientific notation: x 101 Binary scientific notation: x 24 Hence it consists of a sign bit, a mantissa field, and an exponent field. mantissa exponent mantissa CSCE 106

17 Next lecture will be about Problem Solving Methods
CSCE 106


Download ppt "Computer Representation of Information"

Similar presentations


Ads by Google