Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITEC 352 Lecture 7 Binary(2). Review Homework due on Friday Questions Binary Addition Subtraction Encoding.

Similar presentations


Presentation on theme: "ITEC 352 Lecture 7 Binary(2). Review Homework due on Friday Questions Binary Addition Subtraction Encoding."— Presentation transcript:

1 ITEC 352 Lecture 7 Binary(2)

2 Review Homework due on Friday Questions Binary Addition Subtraction Encoding

3 Binary (2) Outline Two’s complement Excess notation Floating point format

4 Binary (2) Two’s complement Similar to one’s complement Solves issues –No double 0 –Addition / subtraction are the same Small conversion cost –Copy all 0’s from right to left –Copy first one –Flip all other bits

5 Binary (2) Class discussion Represent the following in one’s complement and 2’s complement: -9 -7 7 9

6 Binary (2) Excess Representation Which one of the following two numbers represented in 1’s complement is greater? 1011 (or) 0100 What are the steps you had to go through to figure this out? We can avoid these steps by using an excess representation.

7 Binary (2) Excess representatio n Key idea: Make all negative numbers positive by shifting them up …. E.g., Suppose we want to represent numbers from -4 to +3. How do we make all negative numbers positive but at the same time preserving the difference in magnitudes between 2 numbers? We could do this by adding “+4” to all the numbers. Therefore, -4 becomes 0 -3 becomes 1 … 0 becomes 4 … 3 becomes 7 Because we shifted the numbers by 4, we call this Excess 4 representation

8 Binary (2) Excess Representatio n How does this help? Well consider, the question we asked earlier: Which one of the following two numbers is greater? 0000 or 0011 ? “0000” in Excess 4 representation is -4. 0011 is -1. Comparing numbers becomes easier when Excess notation is used.

9 Binary (2) Excessiven ess The “bias” or “excess” (e.g., 4 in the previous slide) can be any number. Usually the bias is the smallest number that we would like to represent. E.g., if we want to represent numbers from -128 to +127, we will use Excess 128 representation. Because we need to consider “0”, we are stopping at 127 and not 128.

10 Binary (2) SUMMARY: Representing negative numbers in a 3 bit architecture (example)

11 Binary (2) Real numbers Numbers of the form: 101.1110101101101011001010101101010. Contain a fractional part. Why even bother with real numbers? Isn’t this some esoteric stuff that is never used??

12 Binary (2) Rationale Floating point computations are everywhere –more common than simple integer computations. Examples: –Any engineering discipline: e.g., Construction industry –Computer security (e.g., random number generation) –Computer games (several graphical computations) Closer to reality: –My experience: NUMBER 1 reason why student programs don’t work in Programming contests!!

13 Binary (2) Real number problem How to store infinitely many floating point numbers into a finite number of bits. Consider a 34 digit binary number: 101.1110101101101011001010101101010 How can we store this in a computer whose bus width is 32?

14 Binary (2) Real number Numbers Consider a 34 digit binary number: 101.1110101101101011001010101101010 How can we store this in a computer whose bus width is 32? Option 1: Split it into two parts (2 X 32-bit integers). Problem: Slows handling of arithmetic operations. Why? Option 2: Sacrifice some precision. This is the idea behind a real number representation called floating point numbers Can you come up with your own standard?

15 Binary (2) Standards Come up with a standard such that the numbers: 10.101 10.100 Can be represented within 4 bits. Can your standard now represent: 100.11

16 Binary (2) Real numbers A common way of representing real numbers is using “floating point numbers”. E.g., –real number: 352.452 –Floating point number representations: 3.52452 * 10 2, or 35.2452 * 10 1, or 0.352452 * 10 3

17 Binary (2) Floating point –A real number: 352.452 can have many Floating point number representations: 3.52452 * 10 2, or 35.2452 * 10 1, or 0.352452 * 10 3 To standardize the position of the floating point – it is normally represented as: –3.52452 * 10 2 (only one digit to the left of the floating point).

18 Binary (2) Examples Normalize the following numbers in base 10: 2345.452 How about in base 2: 101.1110 1111.0111

19 Binary (2) Base 10 More terms: Precision: number of digits in the significand -- sometimes fractions are too large – we need to approximate. The precision tells us by how much. Range: Number of digits in the exponent. Example Consider the number: 60234.45 if precision is 4 and range is 2 then this number is represented as: +(6.023 X 10 23 ):

20 Binary (2) Base 2 Floating Point Consider the binary numbers: 10.101 10.100 0.1001 What is their normalized representation if precision = 4 and range = 2? Do you see any error?

21 Binary (2) Base 2 Floating Point Numbers Consider the binary numbers: 10.101 10.100 What is their representation if precision = 4 and range = 2? Do you see any error? Error is called the rounding error. Every programming language suffers from this.

22 Binary (2) How to live with error. Floating point computations result in rounding errors (precision errors). However, the key is: be consistent with errors. For this, every language/architecture must follow one standard (so that the error is repeatable). –Most famous standard = IEEE 754 standard

23 Binary (2) Summary Two’s complement Excess notation Buildup to floating point numbers


Download ppt "ITEC 352 Lecture 7 Binary(2). Review Homework due on Friday Questions Binary Addition Subtraction Encoding."

Similar presentations


Ads by Google