Download Week-03.2

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Infinity wikipedia , lookup

Infinitesimal wikipedia , lookup

Bra–ket notation wikipedia , lookup

History of logarithms wikipedia , lookup

Musical notation wikipedia , lookup

Abuse of notation wikipedia , lookup

Real number wikipedia , lookup

Big O notation wikipedia , lookup

History of mathematical notation wikipedia , lookup

Rounding wikipedia , lookup

Large numbers wikipedia , lookup

Approximations of π wikipedia , lookup

Location arithmetic wikipedia , lookup

Addition wikipedia , lookup

Arithmetic wikipedia , lookup

Elementary mathematics wikipedia , lookup

Positional notation wikipedia , lookup

Transcript
Dale & Lewis Chapter 3
Data Representation
Representing Real numbers
• Need to represent numbers such as 0.543 or -17.45
• The decimal system uses the “decimal point”
• Remember the definition of a number system, but
extended to negative exponents
dn-1 x bn-1 + dn-2 x bn-2 + … + d2 x b2 + d1 x b1 + d0 x b0
+ d-1 x b-1 + d-2 x b-2 + …
• So 0.543 is 0 x 100 + 5 x 10-1 + 4 x 10-2 + 3 x 10-3
• The decimal point position delimits where the exponents
become negative
Conversion from binary to decimal
• Use the definition of a number in a positional number
system with base 2
• Evaluate the formula using decimal arithmetic
• Example
10.1011 = 1 x 21 + 0 x 20 + 1 x 2-1 + 0 x 2-2 + 1 x 2-3 +
1 x 2-4
= 2 + 0.5 + 0.125 + 0.0625 = 2.6875
• Generalizing, the “decimal point” is called radix point in
non-decimal number systems
Conversion from decimal to binary
• Integer part: convert separately, as done before
• Fractional part:
− Repeatedly multiply by 2
− Integer part is the next digit
− Fraction is developed left to right
• Example: convert 3.14579 to binary
• Integer part is 11
.14579 x 2 = 0.29158
.0
.29158 x 2 = 0.58316
.00
.58316 x 2 = 1.16632
.001
.16632 x 2 = 0.33264
.0010
etc...
3.14579 in binary is 11.0010…
Rounding errors
• Try representing .1 (decimal) into binary
• How would one represent fractions with base 5 or 3?
• Infinite sequences, a computer with fixed number of bits
will make an approximation in the representation
• Needs to be taken into account, or it will lead to rounding
errors  Patriot missile system
Floating point numbers
• Real numbers are represented using a concept inherited from
scientific notation
• Scientific notation is a way of writing numbers that are too big
or too small to be conveniently written in decimal form
• The following all represent +1234.56
+123456.0
+12345.6
+1234.56
+123.456
+12.3456
+1.23456
+0.123456
+0.0123456
x10-2
x10-1
x100
x101
x102
x103
x104  standard representation
x105
Floating point numbers
• The representations differ in that the decimal point “floats”
to the left or right by adjusting the exponent
• Any real number x can be written as
x = ±f x be
where b > 1 is the base, e is an integer for the exponent,
and the fraction is 1/b ≤ f < 1 (normalized)
• We know how to express each part in binary, but
convention for the integer e uses Excess notation
Excess notation
• Another way to express integers (we’ve seen signmagnitude and two’s complement)
• This shifts the list of numbers represented by bits to
include negative numbers, with 10…0 representing 0
• Convert binary excess-n to decimal: (binary value)-n
− Example for excess-8: 0101  5-8 = -3
• Convert decimal to binary excess-n: (decimal value)+n
− Example for excess-8: 6  6+8 = 1110
Excess notation
Floating point numbers in binary
• An example for “single precision” binary floating point
number (32 bits)
− S is the sign: 0  positive, 1  negative
− E is the exponent (here in 8 bits, 256 values, excess-128
notation)
− M is the manitssa (fractional part) has an implicit radix point
at the beginning (here 23 bits, 8,388,608 values)
SEEEEEEEEMMMMMMMMMMMMMMMMMMMMMMM
10010100101010011101001010001101
is -.01010011101001010001101 x 2-87
Floating point number examples
• Using 8-bit floating point representation (SEEEMMMM)
− Convert 3.14579 to binary
3.14579 = 11.0010…
11.0010… x 20
.110010… x 2+2
 01101101 (rounded)
− Convert 0.1 to binary
0.1 = 0.0001100110011…
.0001100110011… x 20
.1100110011… x 2-3

00011101 (rounded)