1 / 21

Fractional Numbers in Numeral Systems

Fractional Numbers in Numeral Systems. Binary nature of the computer. Data is stored in an electronic computer in “little lights” which we represent by bits: 1 and 0. Data may consist of:

janae
Télécharger la présentation

Fractional Numbers in Numeral Systems

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. Fractional Numbers in Numeral Systems

  2. Binary nature of the computer • Data is stored in an electronic computer in “little lights” which we represent by bits: 1 and 0. • Data may consist of: • Character (text) data. It is encoded using some standard code. (Each code can be interpreted as a number.) • Numeric data.It is also encoded in bits using a base 2 numeral system in a way that facilitates performing arithmetic operations (+ - × ÷ ). • Because everything can be interpreted as a number – the thing is a computer !

  3. Binary numerals are easier to record in hex • The binary numeral 1100100101000111010111 takes up space without giving a lot of information. Splitting it into bundles of 4 bits: 0011 0010 0101 0001 1101 0111(adding two 0’s to the front for completeness)written in hex notation is 3 2 5 1 D 7the place values for the hex representation are 165 164 163 162 161 160 • 1048576 65536 4096 256 16 1 • [Check these against the binary powers of 2, 16 = 24]

  4. Easily recognizable binary numbers • The binary numbers 10, 100, 1000, 10000, 100000, 1000000, …are all obviously powers of 2: 21, 22, 23, 24 , 25, 26 ,… • The numbers 1, 11, 111, 1111, 11111, 111111, …are clearly one short of the previous set and so are 21 -1, 22 -1, 23 -1, 24 -1 , 25 -1, 26 -1,…but they also are sums of the previous set. For example: • 111111 = 100000 + 10000 + 1000 + 100 + 10 + 1, • or in decimals: • 26 - 1 = 25 + 24 + 23 + 22 + 21 + 1

  5. We have proved a mathematical fact:

  6. Decimal Numeral System • The base is 10 • The digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 • The place value of each digit is a power of 10: e.g in 62745.28 7 has a place value of 10, 6 has a place value of 104 = 10,0008 has a place value of 10-2 = 1/100 • The expanded form is the sum of the powers of the base (useful when dealing with other bases): 275.45 = 2´102 + 7´101 + 5´100 + 4´10-1 + 5´10-2

  7. Binary Numeral System • The base is 2. • The digits are 0, 1 • The place value of each digit is a power of 2: e.g in 110.101 the place values from left to right are 22, 21, 20, 2-1, 2-2, 2-3 or 4, 2, 1, 1/2, 1/4, 1/8 • The expanded form is the sum of the powers of the base: 110.101 = 1´22 + 1´21 + 0´20 + 1´2-1 + 0´2-2 +1´2-3 = 4 + 2 + 0 + 0.5 + 0 + 0.125 (in decimal) = 6.62510 = 110.1012 (subscripts indicating base)

  8. Base 2 numeral system • In a base 2 numeral system every digit is 2 times as large as the digit immediately to its right. For example, the place values of the bits 1 0 0 1 1 0 1are 26 25 24 23 22 21 20 • The same pattern is followed for fractional numbers (to the right of a binary point) 1 0 0 1 1 0 1 . 0 1 1 26 25 24 23 22 21 20 2-1 2-2 2-3

  9. Binary to Decimal • What is the place value of the bold 0 in 11001.1012 ? Convert the numeral to a decimal one. This is the second position to the right of the point \ the place value is the unit value divided by the second power of 2, that is 2-2 = 1/4. 11001.1012 = 1´24 + 1´23 + 0´22 + 0´21 +1´20 + 1´2-1 + 0´2-2 + 1´2-3 = 1´16 + 1´8 + 0´4 + 0´2 +1´1 + 1´(1/2) + 0´(1/22) + 1´(1/23) = 25+(5/8) = 25.62510

  10. Decimal to binary • Taking out powers of 2. • For example, to convert 18.12510 to binary, the range of powers will be from 4 down to -4 (say)The powers are • 16 8 4 2 1 0.5 0.25 0.125 0.0625From 18.125 take out a 16 to get 10000.0000 in binary with 2.125 left over. Take out 2 to get 10010.0000 with 0.125 left over. • There is no 0.5 or 0.25 and one 0.125 with nothing left over.Thus we have 18.12510 = 10010.0012

  11. From Binary to Hex • To convert 1011110.0112 to hexadecimal, group into fours from the right on the left of the point and from the left to the right of the point: • (0 1 0 1) (1 1 1 0) . (0 1 1 0) • Read each group to base 16: 5 14 . 6 • or 5E . 616 = 5(16)+14+6/16 = 94+3/8 = 94.37510 Note that the trailing 0 is important in the fractional part !

  12. From Hex to Binary • To convert E79.A316 to binary, write each digit in binary notation: • E79.A316 = (1110)(0111)(1001).(1010)(0011) = 111001111001 . 101000112 = 14(256)+7(16)+9+10/16+3/256 = 3705+163/256 = (8+4+2)28 + (4+2+1)24 + (8+1) + (8+2)/24 + (2+1)/28 = 211 + 210 + 29 + 26 + 25 + 24 + 23 + 20 + 2-1 + 2-3 + 2-7 + 2-8

  13. Decimal  Binary via hex • 94.378 is 5(16) + 14 + 6/16 +0/162 + 12/163 + … • 5E.60C… = 01011110.011000001100… • 1011110.0112 to hexadecimal, group into fours from the right on the left of the point and from the left to the right of the point: • (0 1 0 1) (1 1 1 0) . (0 1 1 0) • Read each group to base 16: 5 14 . 6 • or 5E . 616 = 5(16)+14+6/16 = 94+3/8 = 94.37510 Note that the trailing 0 is important in the fractional part !

  14. Dichotomy • A dichotomy is a situation in which there are two possible states of being : vertebrate or invertebrate; male or female; right or wrong; good or bad; on or off; 1 or 0, etc. • A binary decision is a choice made between the two states of a dichotomy. • Binary decisions can be made by computers • – current will flow if there is charge and a path – • and the result can be stored. • The question for decision is often presented as a proposition which should be determined as being either true or false; for example, (3+2) > √26 is false. • If 1 represents true and 0 false, the outcome to the proposition (3+2) > √26 is 0.

  15. Successive binary decisions can give precise values e.g. for √2 • Fact: if x2 is bigger than y2 then x is bigger than y. • Suppose s is the square root of 2, then s2 = 2. Is s bigger than 1 ?… yes because 12 < 2. Is s bigger than 1+1/2 ?… no because 1.52 > 2. Is s bigger than 1+0/2+1/4 ?… yes because 1.252 < 2. Is s bigger than 1+0/2+1/4+1/8?… yes because 1.3752 < 2. Is s bigger than 1+0/2+1/4+1/8+1/16?… no because 1.43752 > 2. Answers so far : 1 0 1 1 0 Is s bigger than 1 + 0/2 + 1/4 + 1/8 + 0/16 + 1/32 ? etc.

  16. Computation of binary expansion for √2 • The sequence of decisions (1 for yes, 0 for no) is 1 0 1 1 0 1 0 1 0 0 0 0 0 1 0 0 1 . . .It stores the place values which show that s is greater than the sum of the indicated powers of ½ • 20 2-2 2-3 2-5 2-7 2-13 2-16 • 1.0110101000001001… is called the binary expansion of √2Note the use of the binary point. • The decimal equivalent is the sum of 20,2-2,2-3,2-5,2-7,2-13,2-16 or 1.41419983… (cf. 1.41421356…)

  17. For example, 23.71> 25 (32) or higher power No 0 > 24 (16) Yes 1 > 24+23 (24) No 0 > 24+22 (20) Yes 1 > 24+22+21 (22) Yes 1 >24+22+21+20 (23) Yes 1 Integer part: 10111. >23+2-1 (23.5) Yes 1 >23+2-1+2-2 (23.75) No 0 >23+2-1 +2-3 (23.625) Yes 1 >23+2-1 +2-3 +2-4 (23.6875) 1 >23 + 0.71875 0 >23 + 0.703125 1 >23 + 0.7109375 0 . . . Binary representation of any number It is possible to find the binary representation of any number by asking questions about its size. 23.71 has binary representation 10111.1011010…

  18. Binary representations • The place values in a binary representation go up in powers of 2 to the left of the binary point and down by powers of 2 to the right, just as with decimals which grow by a factor of ten for a shift of one position to the left.

  19. Binary to decimal conversion • What “we” need to do is: • write down the list of required powers; • multiply the powers by the bits; • add up to get the result. • (The sum of corresponding products is sometimes called the dot product)Notice how convenient it is that bits are numbers and not arbitrary symbols like F and T .

  20. Storing numbers in a computer • Obviously the bits of the binary representation of a number , e.g. 10111.1011010… will be stored for the number in a computer, but what do we do about the binary point, or the minus sign for a negative number, and what do we do about binary expansions that never terminate? • We will return to these questions later, but before that we examine, in the next session, the process of recovering the decimal representation from the binary form – and what might be needed to program a computer to do the job for us.

  21. What’s the big idea? • The point, whether it’s a binary point or a decimal point, determines what we will call the unit. Numerals to the left of it represent multiples of the unit, numerals to the right represent fractions of the unit. The numeral to the left of another has 2 times (for binary), 10 times (for decimal), 16 times for hexadecimal, 60 times (for sexagesimal) and in general b times (for base b numeral system) the value (irrespective of the point). • Computers can make binary decisions (and store them)

More Related