130
Boolean Algebra

Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Embed Size (px)

Citation preview

Page 1: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Boolean Algebra

Page 2: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Starter Task

• State 5 basic data types together with one operation that can be performed on each.

• We have looked at 4 in the past few weeks...

Page 3: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few
Page 4: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Answers

• Variable• Array

– Insert a value into a certain position in the array• Stack

– Pop, Push• Queue

– enQueue, Serve• Binary Tree

– Search through and add values / Delete values• Linked List

– Add items to the list, remove items from the list

Page 5: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Over the next Few Weeks...• Working through the booklets...

• Binary Numbers• Hexadecimal Numbers• Characters• ASCII – Strings and Character sets• Negative Numbers

• Two’s complement, representation sign, magnitude

• Shifting• Fixed Point, Floating Point

– Conversion + Benefits• Rounding + Truncation effects on accuracy• Overflow, Underflow

Page 6: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

We use Base 10...

• Because we have 10 fingers

Page 7: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

What if we had 16?

Page 8: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

This gives us the structure of...

• Every 10th value we add an extra number...– 2– 12– 23– 178– Etc...

Page 9: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Base 10 looks like...

• The number 1583 means 1 'thousand', 5 'hundreds', 8 'tens' and 3 'units'...

Page 10: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Where each column is 10^X

• 10^1 = 10• 10^2 = 100• 10^3 = 1000• 10^4 = 10,000

Page 11: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Consider this...

• Computers only use base 2...

• How would this look in a table?

• What will a base 2 set of numbers look like?

Page 12: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Base 2

Page 13: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Base 2

128 64 32 16 8 4 2 1

Page 14: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Representing numbers...

• What number do you think this will represent?

• 10010110

Page 15: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Base 2

128 64 32 16 8 4 2 1

1 0 0 1 0 1 1 0

Page 16: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

•150

Page 17: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

What do the following numbers =

• 10000101• 01000001• 11111111• 10110101• 00000000• 10101111• 00101010• 00111011• 10111010

Page 18: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Answers

• 10000101 = 128 + 0 + 0 + 0 + 0 + 4 + 0 + 1 = 133

• 65• 255• 181• 0• 175• 42• 59• 186

Page 19: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

What if I wanted to go the other way...

• How would I convert 22 into binary?

128 64 32 16 8 4 2 1

Page 20: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Actions

• 22 / 2 = 11 r 0

• _ _ _ _0

Page 21: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Actions

• 22 / 2 = 11 r 0• 11 / 2 = 5 r 1

• _ _ _10

Page 22: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Actions

• 22 / 2 = 11 r 0• 11 / 2 = 5 r 1• 5 / 2 = 2 r 1

• _ _110

Page 23: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Actions

• 22 / 2 = 11 r 0• 11 / 2 = 5 r 1• 5 / 2 = 2 r 1• 2 / 2 = 1 r 0

• _ 0110

Page 24: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Actions

• 22 / 2 = 11 r 0• 11 / 2 = 5 r 1• 5 / 2 = 2 r 1• 2 / 2 = 1 r 0• 1 / 2 = 0 R 1

• 1 0110

Page 25: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

What if I wanted to go the other way...

• How would I convert 22 into binary?

128 64 32 16 8 4 2 1

0 0 0 1 0 1 1 0

Page 26: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Actions

• Divide each value into largest number and put a one in the table...

Page 27: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

What are the following binary numbers?

• 156• 45• 78• 97• 123• 245• 253• 7• 184• 111

Page 28: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

What are the following binary numbers?

• 156 = 10011100• 45 = 00101101• 78 = 01001110• 97 = 01100001• 123 = 01111011• 245 = 11110101• 253 = 11111101• 7 = 00000111• 184 = 10111000• 111 = 01101111

Page 29: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Bytes

• So far everything has consisted of once byte... • 8 bits... Byte

• 4bits... Nybble (rarely used now)• 1101=13

Page 30: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Standard Computers are 32bit...

• What would be the maximum value that a 32bit computer can hold?

• You might want to use a calculator...

Page 31: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

• 32 bit = 4,294,967,295

• This is the biggest value for a 32bit computer...• However it doesn’t exist in many operating

systems...

Page 32: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

64Bit...

• What about 64bit?

Page 33: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Again...

• 18,446,744,073,709,552,000

• This number will not be found in 64bit operating systems...

• Can you look down the list of contents in the booklet to see why?

Page 35: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Convertor

• http://mistupid.com/computers/binaryconv.htm

Page 36: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Lesson 2

• Hexadecimal notation...

• What do you think hexadecimal notation looks like?

Page 37: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Hexadecimal notation1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

0 1 2 3 4 5 6 7 8 9 A B C D E F

Page 38: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

What’s it used for

• Give a more readable notation for people to use.

• Decimal = 10,995• Binary = 10101011110011• Hexadecimal = 2AF3

Page 39: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

How it’s used...

• Have you ever seen...• #33FD56

• In HTML coding...• Gives you a colour• #33FD56

Page 40: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Each part = nybble

•#33FD56•33 = 51 =0011 0011•FD = 253 =1111 1101•56 = 86 =0101 0110

Page 41: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Task 2

• Fill in the table: You will have to remember how to complete binary numbers...

Page 42: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Now we have 3 ways to represent numbers...

• What is the point?

• We can represent 0-255 numbers using 1byte or 1 hexadecimal code

• Can you think of why we would use this?

Page 43: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Character Sets

• All the symbols, letters, numbers have a binary representation

• There are 128 different characters that we call

ASCIIThis is a Standard!

Page 44: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

ASCII

• (American Standardised Code for Information Interchange)

• Needed so that computers share documents together:

Others include:EBCDIC (Extended Binary Coded Decimal Interchange Code)

ISO 8859, for ß (German), ñ (Spanish), å (Swedish)ANSI (American National Standards Institute)

Page 45: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

ASCII Character Set

Page 46: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Words

• In order to write the word Hello

Page 47: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Task

• How would hello world read?

• How many bits are used for each character?

Letter

H E L L O W O R L DNumber

Binary

Page 48: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Hello World

• 01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100

Page 49: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Hello World

• 48 65 6c 6c 6f 20 57 6f 72 6c 64

Page 50: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Practice

• What about the sentence:

• There are 10 types of people in the world: those who understand binary, and those who don't.

Page 51: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Thankful for abstraction?

• Imagine trying to code in binary...

Page 52: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Abstract a little

• Hollerith Punch Card

Page 53: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Tools

• http://home2.paulschou.net/tools/xlate/

Page 54: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Monkeys

• We don’t need to be intelligent to talk binary

Page 55: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Summary

• What is binary?

• How can we use binary?

• What is Hexadecimal?

• Why is it used?

Page 56: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Lesson 3

• Negative numbers?

• What is the Largest and smallest numbers that you can have?

Page 57: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Negative numbers

• Need to put in the minus sign –

• Sign/Magnitude • Two’s complement

Page 58: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Sign/Magnitude Representation

• We have 8 bits• 10010101

• The first represents the sign:• 10010101

Page 59: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Converting Binary

• -26• 26/2 = 13 r 0• 13/2 = 6 r 1• 6 / 2 = 3 r 0• 3 / 2 = 1 r 1• 1 / 2 = 0 r 1

11010

Page 60: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

8 bit information

• Take our number: 11010• It is negative: -26

• Starts with a 1, then put 0’s in and then the number...

• 10011010

Page 61: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Practice

• a) -3 • • b) -10 • • c) -62 • • d) 62 • • e) 13 • • f) 128

Page 62: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Answers

• a) -3 = 10000011• • b) -10 = 10001010• • c) -62 = 10111110• • d) 62 = 00111110• • e) 13 = 00001101• • f) 128 = 10000000

Page 63: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

What are the issues with this?

• What is the problem with representing 128?

• How would we type in -128

• What is the main limtation?

Page 64: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Problems

• Halves the amount of numbers that you can have...

Page 65: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

This is why it is rarely used any more.

• Sign/Magnitude has/is being phased out

• Two’s Complement is the new thing!

Page 66: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Two’s Compliment

• How else could we represent negative numbers?

Page 67: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Count down, and reset the clock

Page 68: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

So to work out a number:

• Find the number in Binary as (-)35:– 100011

• Find the complement:– 011100

• Add 1 to the value:– 011100– 000001– 011101

Page 69: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Convert the following numbers

• 55• 111• 19• 27• 79• 88

• Can you spot a trend with these number?

Page 70: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Answers

• -55 = 11001001• -111 = 10010001• -19 = 11101101• -27 = 11100101• -79 = 10110001• -88 = 10101000

• Can you spot a trend with these number?

Page 71: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Convertor

• http://www.rsu.edu/faculty/PMacpherson/Programs/twos.html

Page 72: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Math with Binary

• Works just like denary Math...

• When you add one, it increase’s the value:

• Add 1 to 199

Page 73: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Adding

199001 + 200

Page 74: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Same kind of thing for Binary

• 88 = 01011000• Complement = 10100111

000000011 + 1 = 0 r 10

1

Page 75: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Same kind of thing for Binary

• 88 = 01011000• Complement = 10100111

000000011 + 1 = 0 r 100

1

Page 76: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Same kind of thing for Binary

• 88 = 01011000• Complement = 10100111

000000011 + 1 = 0 r 1000

1

Page 77: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Same kind of thing for Binary

• 88 = 01011000• Complement = 10100111

000000010 + 1 = 1 r 01000

0

Page 78: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Same kind of thing for Binary

• 88 = 01011000• Complement = 10100111

000000010 + 0 = 0 r 001000

0

Page 79: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Same kind of thing for Binary

• 88 = 01011000• Complement = 10100111

000000010 + 1 = 1 r 0101000

0

Page 80: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Same kind of thing for Binary

• 88 = 01011000• Complement = 10100111

000000010 + 0 = 0 r 00101000

0

Page 81: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Same kind of thing for Binary

• 88 = 01011000• Complement = 10100111

000000011 + 0 = 0 r 0101010000

Page 82: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Your Turn

• Try Converting these• -18 • -64• -19• -16• 58

Page 83: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Answers

• Try Converting these• -18 = 11101110 • -64 = 11000000• -19 = 11101101• -16 = 11110000• 58 = 00111010

Page 84: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Summary

• Sign / Magnitude

• Two’s Compliment

• Adding Binary Numbers together

Page 85: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Shifting

• As the name implies:

• Moving items along:

• Try the task in the booklets...

1011010 1101101 0110110

Shift Left Shift Right

Page 86: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Shifting

• 10001101 – Shift Left - 00011010• 10010101 – Shift Right - 01001010• 00010101 – Shift Left - 00101010• 10010101 – Shift Left - 00101010• 10010110 – Shift Right - 01001011• 01101010 – Shift Left - 11010110

Page 87: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Shifting

• 2 Types

• Logical Shift • Arithmetic Shift

Page 88: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Logical Shift

• Need a set of binary:– Carry Flag:

• Everything either goes left / right• The item that drops off the list gets put in the

Carry Flag

Page 89: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Logical Shifting

• 10001101 – Shift Left - 00011010• 10010101 – Shift Right - 01001010• 00010101 – Shift Left - 00101010• 10010101 – Shift Left - 00101010• 10010110 – Shift Right - 01001011• 01101010 – Shift Left - 01101010

Carry Flag

110100

Page 90: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Arithmetic Shift

• Similar to the Logical Shift except:

Page 91: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Arithmetic Shifting

• 10001101 – Shift Left - 00011011• 10010101 – Shift Right - 11001010• 00010100 – Shift Left - 00101000• 10010101 – Shift Left - 00101011• 10010110 – Shift Right - 11001011• 01101010 – Shift Left - 11010100

Carry Flag

110100

Page 92: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Look at the shifting task...

00110101 = 0110101010110010 = 01011001

00101110 = 0001011111001011 = 10010111

Carry Flag

00

01

Page 93: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Next Task

• Perform the following steps, converting the number to see what happens...

Page 94: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Answers

1. 622. 1243. 2484. 31

Page 95: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Practice

• Using an Array of 1’s or 0’s can you code an arithmetic shift to the left or the right?

• Create an array : binary(10)• Populate it with numbers– For i as integer 1 to binary.length-1

• Shift to the left =– For i as integer 1 to binary.length-1

• Binary(binary.length – i) = binary(binary.length – i+1)

– Next

Page 96: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Shifting

• Summary

• Shifting is useful because?

Page 97: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Lesson 5

• Complete the binary task in the booklets

• 11• 15• -95• 185• -34• -15

Page 98: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Answers

• 11 = 00001011• 15 = 00001111• -95 = 10100001• 125 = 01111101• -34 = 11011110• -15 = 11110001

Page 99: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Lesson 5

• Floating Point

• Using “binary” places to represent numbers...

Page 100: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

In Decimal

• In denary the integer 25000 can be written as• 2.5 x 104

• This has the structure of: – Unit.Decimal x 10 ^ X

– Mantissa x 10 Exponent

Page 101: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

This can also be applied to binary

• Mantissa x 10 Exponent

• First step – we need to get the number in its lowest form...

• This is achieved through halving

= 20 x 21

= 10 x 22 = 5 x 23 = 2.5 x 24

= 1.25 x 25

= 0.625 x 26

Page 102: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Golden Rule

• Need to get the mantissa to a value between 0.5 and 1

• = 0.625 x 26

Page 103: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

• A floating point number system uses 16-bit numbers.

• 8 bits for the (signed)mantissa, and 8 bits for the (signed) exponent.

• 01010001 00000101

Page 104: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

How this works...

• 0.625 x 26

• Means – 0.625 arithmetically shifted right 6 times...

• To get back to the number we must shift it left 6 times

Page 105: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

01010000 00000110

Sign 1/2 1/4 1/8 1/16 1/32 1/64 1/128

0 1 0 1 0 0 0 0= 0.625

= 6

= Mantissa

= Exponent

Sign 4 2 1

0 1 1 0

Page 106: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

This is like saying

•01010000 x 2 00000110

Page 107: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Task 1

• Can you represent 24 as a binary number?

Page 108: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

24

Sign 1/2 1/4 1/8 1/16 1/32 1/64 1/128

0 1 1 0 0 0 0 0= 0.75

= 5

= Mantissa

= ExponentSign 4 2 1

0 1 0 1

Page 109: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

How about 0.0625

Page 110: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

0.0625

Sign 1/2 1/4 1/8 1/16 1/32 1/64 1/128

0 1 0 0 0 0 0 0= 0.5

= -3

= Mantissa

= ExponentSign 4 2 1

1 0 1 1

Page 111: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

-14

Page 112: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

-14

Sign 1/2 1/4 1/8 1/16 1/32 1/64 1/128

1 1 1 1 0 0 0 0= -0.875

Sign 4 2 1

0 1 0 0= 4

= Mantissa

= Exponent

Page 113: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Whats the difference with these numbers?

• Can you see how these would be used instead of previous numbers that we have looked at?

• You have used these before...

Page 114: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Real Numbers

• Whenever you declare a double then you are going to be using floating point numbers.

• The Mantissa and the exponent can change in length depending on the definitions placed upon it.

Page 115: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Conversion Techniques

• You start with the Mantissa

• If the Exponent is +ve– Shift to the left

• If it’s negative– Shift to the right

Page 116: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Can you use these examples to convert back?

• 01010001 0101• 011010000 0110

Page 117: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Answer

• 19.25• 104

Page 118: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Floating Point Numbers

• Pro’s– A much wider range of numbers can be declared

• Con’s– More Space is required to use them– Slower Processing Times– Lack of Precision

• some real numbers can only be represented approximately

Page 119: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Range

• To increase the range you increase the mantissa

• To increase the precision you increase the mantissa

Page 120: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Lesson 6

• Start the task...

Page 121: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Answers

• 12 = 01100000 0100

• 9.76 – Can this be done?

• Can you convert 0.1 into a decimal?

Page 122: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Rounding

• For example, 1.36 rounded to one decimal place is 1.4 giving a rounding error of 0.04.

• This can be done in binary too however there are many different ways that this can be done...

Page 123: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

If we round the following binary number...

• 10101

• 4 b.p.

• 2 b.p.• What do we get?

Page 124: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Your Turn

Page 125: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Truncation

• For example, 1.36 truncated to one decimal place is 1.3 giving a truncation error of 0.6.

• Shift the number to the right 3 places..., then back to the left 3 places

• 01101001

Page 126: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Your Turn

• Truncate the numbers,

• Find a rule for the amount of error within truncation.

Page 127: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Error Accumulation

• If you round 1.356 to 2 decimal places the rounding errors is ………?

• If you then multiply the result by 1000 the rounding error becomes ……?

Page 128: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Overflow

• Using 8bit integer perform the following calculation...

• 150+130

• Represent the answer as binary

Page 129: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Overflow

• Convert the following numbers...• Add the following numbers together and then

convert the answer...

• Is this right?

Page 130: Boolean Algebra. Starter Task State 5 basic data types together with one operation that can be performed on each. We have looked at 4 in the past few

Summary

• There are issues with binary representation

• Good programming languages will warn you of this...

• Needs to be handled by the developer.