html5-img
1 / 11

Lecture 10

Lecture 10. Binary numbers – for fractional numbers. Negative Integers. One method of representing negative numbers is called Sign-Magnitude Give up the leftmost bit to be used for a “sign” A 1 in the leftmost bit means the number is negative. 1011 is -3

banyan
Télécharger la présentation

Lecture 10

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. Lecture 10 Binary numbers – for fractional numbers

  2. Negative Integers • One method of representing negative numbers is called Sign-Magnitude • Give up the leftmost bit to be used for a “sign” • A 1 in the leftmost bit means the number is negative. • 1011 is -3 • If you are using this method, what happens when you add the positive numbers 7 and 2? • 0111 + 0010 = 1001 !!!

  3. example with 3 bits • In a three bit system, we could get the following representations: • 000 = 0 • 001 = 1 • 010 = 2 • 011 = 3 • 100 = -0 • 101 = -1 • 110 = -2 • 111 = -3

  4. Twos complement • This is the sign magnitude method and gives all the numbers from –(23-1 - 1) to (23-1 - 1) or -22 – 1 to 22 – 1. But it seems wasteful to have two ways of writing zero. • Instead computer scientists have invented two’s complement. When a number has a one in the left most location, it is translated by taking its “complement”, adding 1 and attaching a -1

  5. Fractional numbers • 1011.101 What does this correspond to in base 10? • The place values to the right of the decimal continue to have smaller place values given by 2 raised to a negative exponent • 0.1 in binary is 2-1 = .5 • 0.01 in binary is 2-2 = .25 • 0.001 in binary is 2-3 = .125 • 0.0001 in binary is 2-4 = .0625 • 0.00001 in binary is 2-5 = .03125 • 0.000001 in binary is 2-6 = .015625 • 0.0000001 in binary is 2-7 = .0078125

  6. Converting fractional decimal numbers to binary • Note: Terminating decimal fractions may not have terminating binary representation. • Try converting each of the following • .75 • .1875 • .2 • .6

  7. Fractional numbers • 1011.101 What does this correspond to in base 10? • The place values to the right of the decimal continue to have smaller place values given by 2 raised to a negative exponent • 0.1 in binary is 2-1 = .5 • 0.01 in binary is 2-2 = .25 • 0.001 in binary is 2-3 = .125 • 0.0001 in binary is 2-4 = .0625 • 0.00001 in binary is 2-5 = .03125 • 0.000001 in binary is 2-6 = .015625 • 0.0000001 in binary is 2-7 = .0078125

  8. Storing the Floating Point Binary Number in the Computer • There is of course no decimal point – only 0’s and 1’s. We will have to decide on a code for storing these numbers. • Actual computers use 32 or 64 bits to store a floating point number. But to work by hand, we will assume that we have a “baby” computer that only uses 16 bits. • Recall that 235.67 can be written as .23567x103 • 23567 is the Mantissa • 3 is the Exponent

  9. _ _ _ _ _ _ _ _ _ _ __ _ _ _ _ • The first 10 bits are for the Mantissa with the first bit being the sign • The next six are for the exponent with the first one being the sign. • 1101.011 is written as .1101011x24 • The mantissa is positive so the sign is 0. We have nine more bits for the mantissa so we add 00 to the end getting 0110101100 • The exponent is also positive and we have 4 bits to represent the number 4 giving 000100 • The complete 16 bits: 0110101100 000100

More Related