binary fractions. fractions a radix separates the integer part from the fraction part of a number....

44
Binary Fractions

Upload: miranda-wells

Post on 31-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Binary Fractions

Page 2: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Fractions

A radix separates the integer part from the fraction part of a number.

101.101 Columns to the right of the radix have

negative powers of 2.

Page 3: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Fractions

22 21 20 . 2-1 2-2 2-3

Page 4: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Fractions

22 21 20 . 2-1 2-2 2-3

4 2 1 . ½ ¼ ⅛

Page 5: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Fractions

22 21 20 . 2-1 2-2 2-3

4 2 1 . ½ ¼ ⅛

1 0 1 . 1 0 1

Page 6: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Fractions

22 21 20 . 2-1 2-2 2-3

4 2 1 . ½ ¼ ⅛

1 0 1 . 1 0 1

4 + 1 + ½ + ⅛

Page 7: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Fractions

22 21 20 . 2-1 2-2 2-3

4 2 1 . ½ ¼ ⅛

1 0 1 . 1 0 1

4 + 1 + ½ + ⅛

5⅝

Page 8: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Fractions

Another way to assess the fraction:

4 2 1 . ½ ¼ ⅛

1 0 1 . 1 0 1

Just as this is 5

Page 9: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Fractions

Another way to assess the fraction:

4 2 1 . ½ ¼ ⅛

1 0 1 . 1 0 1

Just as this is 5 so is this!

Page 10: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Fractions

Another way to assess the fraction:

4 2 1 . ½ ¼ ⅛

1 0 1 . 1 0 1Just as this is 5 so is this

Except it’s not 5 ones.

It’s 5 eighths.

Page 11: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Fractions

Another way to assess the fraction:

4 2 1 . ½ ¼ ⅛

1 0 1 . 1 0 1Just as this is 5 so is this

Except it’s not 5 ones.

It’s 5 eighths.

Page 12: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Fractions

But there’s no dot (.) in Binary!

We need to explore a method for storing fractions without inventing another symbol.

Page 13: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Scientific Notation

Very large and very small numbers are often represented such that their orders of magnitude can be compared.

The basic concept is an exponential notation using powers of 10.

a × 10b

Where b is an integer, and a is a real number such that:

1 ≤ |a| < 10

Page 14: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Scientific Notation - examples

An electron's mass is about

0.00000000000000000000000000000091093826 kg.

In scientific notation, this is written:

9.1093826×10−31 kg.

Page 15: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Scientific Notation - examples

An electron's mass is about

0.00000000000000000000000000000091093826 kg.

In scientific notation, this is written:

9.1093826×10−31 kg.

Page 16: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Scientific Notation - examples

The Earth's mass is about

5,973,600,000,000,000,000,000,000 kg.

In scientific notation, this is written:

5.9736×1024 kg.

Page 17: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Scientific Notation - examples

The Earth's mass is about

5,973,600,000,000,000,000,000,000 kg.

In scientific notation, this is written:

5.9736×1024 kg.

Page 18: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

E Notation

To allow values like this to be expressed on calculators and early terminals

‘× 10b’

was replaced by ‘Eb’

So 9.1093826×10−31

becomes 9.1093826E−31

And 5.9736×1024

becomes 5.9736E+24

Page 19: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

E Notation

The ‘a’ part of the number is called the mantissa or significand.

The ‘Eb’ part is called the exponent.

Since exponents could also be negative, they would typically have a sign as well.

Page 20: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Floating Point Storage

In floating point notation the bit pattern is divided into 3 components:

Sign – 1 bit (0 for +, 1 for -)

Exponent – stored in Excess notation

Mantissa – must begin with 1

Page 21: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Floating Point Storage

In floating point notation the bit pattern is divided into 3 components:

Sign – 1 bit (0 for +, 1 for -)

Exponent – stored in Excess notation

Mantissa – must begin with 1

Page 22: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Floating Point Storage

In floating point notation the bit pattern is divided into 3 components:

Sign – 1 bit (0 for +, 1 for -)

Exponent – stored in Excess notation

Mantissa – must begin with 1

Page 23: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Floating Point Storage

In floating point notation the bit pattern is divided into 3 components:

Sign – 1 bit (0 for +, 1 for -)

Exponent – stored in Excess notation

Mantissa – must begin with 1

Page 24: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Mantissa

Assumes a radix point immediately left of the first digit.

The exponent will determine how far, and in which direction to move the radix.

Page 25: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

An example in 8 bits

If the following pattern stores a floating point value, what is it?

01101001

Page 26: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

An example in 8 bits

If the following pattern stores a floating point value, what is it?

01101001Separate it into its components:

Page 27: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

An example in 8 bits

If the following pattern stores a floating point value, what is it?

01101001Separate it into its components:

signexponentmantissa

Page 28: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

An example in 8 bits

If the following pattern stores a floating point value, what is it?

0 110 1001Separate it into its components:

signexponentmantissa

Page 29: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

An example in 8 bits

0 110 1001A sign bit of 0 means the number is…?

Page 30: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

An example in 8 bits

0 110 1001A sign bit of 0 means the number is positive.

110 in Excess Notation converts to …?

Page 31: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

An example in 8 bits

0 110 1001A sign bit of 0 means the number is positive.

110 in Excess Notation converts to +2.

Place the radix in the mantissa …

Page 32: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

An example in 8 bits

0 110 1001A sign bit of 0 means the number is positive.

110 in Excess Notation converts to +2.

Place the radix in the mantissa .1001

Put it all together …

Page 33: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

An example in 8 bits

0 110 1001A sign bit of 0 means the number is positive.110 in Excess Notation converts to +2.Place the radix in the mantissa .1001

Put it all together …

+ .1001 * 22

Page 34: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

An example in 8 bits

+ .1001 * 22

Multiplying a binary number by 2 shifts the bits left (moves the radix to the right) one position.

So this exponent tells us to shift the radix 2 positions right.

+ 10.01

= 2¼

Page 35: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Normal Form

The rule of Normal Form guarantees a unique mapping of patterns onto values.

Page 36: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Normal Form

Consider the following 8-bit pattern in Normal Form:

0 100 1000 0 .1000 .1000

0 101 0100 1 .0100 .1000

0 110 0010 2 .0010 .1000

0 111 0001 3 .0001 .1000

Page 37: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Normal Form

The exponent represents 0 so the radix is moved 0 positions.

0 100 1000 0 .1000 .1000

0 101 0100 1 .0100 .1000

0 110 0010 2 .0010 .1000

0 111 0001 3 .0001 .1000

Page 38: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Normal Form

The exponent represents 0 so the radix is moved 0 positions.

0 100 1000 0 .1000 .1000

0 101 0100 1 .0100 .1000

0 110 0010 2 .0010 .1000

0 111 0001 3 .0001 .1000

Page 39: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Normal Form

Now consider this pattern, which is NOT in Normal Form.

0 100 1000 0 .1000 .1000

0 101 0100 1 .0100 .1000

0 110 0010 2 .0010 .1000

0 111 0001 3 .0001 .1000

Page 40: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Normal Form

The exponent represents +1 so the radix is moved 1 position to the right.

0 100 1000 0 .1000 .1000

0 101 0100 1 .0100 .1000

0 110 0010 2 .0010 .1000

0 111 0001 3 .0001 .1000

Page 41: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Normal Form

The exponent represents +1 so the radix is moved 1 position to the right.

0 100 1000 0 .1000 .1000

0 101 0100 1 .0100 .1000

0 110 0010 2 .0010 .1000

0 111 0001 3 .0001 .1000

Page 42: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Normal Form

But this is the same result as the first example!

0 100 1000 0 .1000 .1000

0 101 0100 1 .0100 .1000

0 110 0010 2 .0010 .1000

0 111 0001 3 .0001 .1000

Page 43: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Normal Form

In fact there are MANY possible ways to represent the same value:

0 100 1000 0 .1000 .1000

0 101 0100 1 .0100 .1000

0 110 0010 2 .0010 .1000

0 111 0001 3 .0001 .1000

Page 44: Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number. 101.101 Columns to the right of the radix have negative

Normal Form

The first bit of the mantissa must be 1 to prevent multiple representations of the same value.

0 100 1000 0 .1000 .1000

0 101 0100 1 .0100 .1000

0 110 0010 2 .0010 .1000

0 111 0001 3 .0001 .1000