Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Boolean Algebra

2 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...

3

4 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

5 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 Two’s complementsign, magnitude Shifting Fixed Point, Floating Point – Conversion + Benefits Rounding + Truncation effects on accuracy Overflow, Underflow

6 We use Base Because we have 10 fingers

7 What if we had 16?

8 This gives us the structure of... Every 10 th value we add an extra number... – 2 – 12 – 23 – 178 – Etc...

9 Base 10 looks like... The number 1583 means 1 'thousand', 5 'hundreds', 8 'tens' and 3 'units'...

10 Where each column is 10^X 10^1 = 10 10^2 = ^3 = ^4 = 10,000

11 Consider this... Computers only use base 2... How would this look in a table? What will a base 2 set of numbers look like?

12 Base 2

13

14 Representing numbers... What number do you think this will represent?

15 Base

16 150

17 What do the following numbers =

18 Answers = =

19 What if I wanted to go the other way... How would I convert 22 into binary?

20 Actions 22 / 2 = 11 r 0 _ _ _ _0

21 Actions 22 / 2 = 11 r 0 11 / 2 = 5 r 1 _ _ _10

22 Actions 22 / 2 = 11 r 0 11 / 2 = 5 r 1 5 / 2 = 2 r 1 _ _110

23 Actions 22 / 2 = 11 r 0 11 / 2 = 5 r 1 5 / 2 = 2 r 1 2 / 2 = 1 r 0 _ 0110

24 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

25 What if I wanted to go the other way... How would I convert 22 into binary?

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

27 What are the following binary numbers?

28 What are the following binary numbers? 156 = = = = = = = = = =

29 Bytes So far everything has consisted of once byte... 8 bits... Byte 4bits... Nybble (rarely used now) 1101=13

30 Standard Computers are 32bit... What would be the maximum value that a 32bit computer can hold? You might want to use a calculator...

31 32 bit = 4,294,967,295 This is the biggest value for a 32bit computer... However it doesn’t exist in many operating systems...

32 64Bit... What about 64bit?

33 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?

34 Summary Video’s Iw Iw ems/Lessons/DecimalToBinaryConversion/ind ex.html ems/Lessons/DecimalToBinaryConversion/ind ex.html

35 Convertor m m

36 Lesson 2 Hexadecimal notation... What do you think hexadecimal notation looks like?

37 Hexadecimal notation ABCDEF

38 What’s it used for Give a more readable notation for people to use. Decimal =10,995 Binary = Hexadecimal= 2AF3

39 How it’s used... Have you ever seen... #33FD56 In HTML coding... Gives you a colour #33FD56

40 Each part = nybble #33FD56 33=51= FD=253= =86=

41 Task 2 Fill in the table: You will have to remember how to complete binary numbers...

42 Now we have 3 ways to represent numbers... What is the point? We can represent numbers using 1byte or 1 hexadecimal code Can you think of why we would use this?

43 Character Sets All the symbols, letters, numbers have a binary representation There are 128 different characters that we call ASCII This is a Standard!

44 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)

45 ASCII Character Set

46 Words In order to write the word Hello

47 Task How would hello world read? How many bits are used for each character? Letter HELLOWORLD Number Binary

48 Hello World

49 Hello World c 6c 6f f 72 6c 64

50 Practice What about the sentence: There are 10 types of people in the world: those who understand binary, and those who don't.

51 Thankful for abstraction? Imagine trying to code in binary...

52 Abstract a little Hollerith Punch Card

53 Tools

54 Monkeys We don’t need to be intelligent to talk binary

55 Summary What is binary? How can we use binary? What is Hexadecimal? Why is it used?

56 Lesson 3 Negative numbers? What is the Largest and smallest numbers that you can have?

57 Negative numbers Need to put in the minus sign – Sign/Magnitude Two’s complement

58 Sign/Magnitude Representation We have 8 bits The first represents the sign:

59 Converting Binary /2 =13 r 0 13/2 =6 r 1 6 / 2=3 r 0 3 / 2=1 r 1 1 / 2=0 r

60 8 bit information Take our number: It is negative: -26 Starts with a 1, then put 0’s in and then the number

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

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

63 What are the issues with this? What is the problem with representing 128? How would we type in -128 What is the main limtation?

64 Problems Halves the amount of numbers that you can have...

65 This is why it is rarely used any more. Sign/Magnitude has/is being phased out Two’s Complement is the new thing!

66 Two’s Compliment How else could we represent negative numbers?

67 Count down, and reset the clock

68 So to work out a number: Find the number in Binary as (-)35: – Find the complement: – Add 1 to the value: – – –

69 Convert the following numbers Can you spot a trend with these number?

70 Answers -55= = = = = = Can you spot a trend with these number?

71 Convertor ograms/twos.html ograms/twos.html

72 Math with Binary Works just like denary Math... When you add one, it increase’s the value: Add 1 to 199

73 Adding

74 Same kind of thing for Binary 88 = Complement = = 0 r 1 0 1

75 Same kind of thing for Binary 88 = Complement = = 0 r

76 Same kind of thing for Binary 88 = Complement = = 0 r

77 Same kind of thing for Binary 88 = Complement = = 1 r

78 Same kind of thing for Binary 88 = Complement = = 0 r

79 Same kind of thing for Binary 88 = Complement = = 1 r

80 Same kind of thing for Binary 88 = Complement = = 0 r

81 Same kind of thing for Binary 88 = Complement = = 0 r

82 Your Turn Try Converting these

83 Answers Try Converting these -18 = = = = =

84 Summary Sign / Magnitude Two’s Compliment Adding Binary Numbers together

85 Shifting As the name implies: Moving items along: Try the task in the booklets Shift LeftShift Right

86 Shifting – Shift Left – Shift Right – Shift Left – Shift Left – Shift Right – Shift Left

87 Shifting 2 Types Logical Shift Arithmetic Shift

88 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

89 Logical Shifting – Shift Left – Shift Right – Shift Left – Shift Left – Shift Right – Shift Left Carry Flag

90 Arithmetic Shift Similar to the Logical Shift except:

91 Arithmetic Shifting – Shift Left – Shift Right – Shift Left – Shift Left – Shift Right – Shift Left Carry Flag

92 Look at the shifting task = = = = Carry Flag

93 Next Task Perform the following steps, converting the number to see what happens...

94 Answers

95 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

96 Shifting Summary Shifting is useful because?

97 Lesson 5 Complete the binary task in the booklets

98 Answers 11= = = = = =

99 Lesson 5 Floating Point Using “binary” places to represent numbers...

100 In Decimal In denary the integer can be written as 2.5 x 10 4 This has the structure of: – Unit.Decimal x 10 ^ X – Mantissa x 10 Exponent

101 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 2 1 = 10 x 2 2 = 5 x 2 3 = 2.5 x 2 4 = 1.25 x 2 5 = x 2 6

102 Golden Rule Need to get the mantissa to a value between 0.5 and 1 = x 2 6

103 A floating point number system uses 16-bit numbers. 8 bits for the (signed)mantissa, and 8 bits for the (signed) exponent

104 How this works x 2 6 Means – arithmetically shifted right 6 times... To get back to the number we must shift it left 6 times

105 Sign1/21/41/81/161/321/641/ = = 6 = Mantissa = Exponent Sign

106 This is like saying x

107 Task 1 Can you represent 24 as a binary number?

108 24 Sign1/21/41/81/161/321/641/ = 0.75 = 5 = Mantissa = Exponent Sign

109 How about

110 Sign1/21/41/81/161/321/641/ = 0.5 = -3 = Mantissa = Exponent Sign

111 -14

112 Sign1/21/41/81/161/321/641/ = Sign = 4 = Mantissa = Exponent

113 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...

114 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.

115 Conversion Techniques You start with the Mantissa If the Exponent is +ve – Shift to the left If it’s negative – Shift to the right

116 Can you use these examples to convert back?

117 Answer

118 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

119 Range To increase the range you increase the mantissa To increase the precision you increase the mantissa

120 Lesson 6 Start the task...

121 Answers 12 = – Can this be done? Can you convert 0.1 into a decimal?

122 Rounding For example, 1.36 rounded to one decimal place is 1.4 giving a rounding error of This can be done in binary too however there are many different ways that this can be done...

123 If we round the following binary number b.p. 2 b.p. What do we get?

124 Your Turn

125 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

126 Your Turn Truncate the numbers, Find a rule for the amount of error within truncation.

127 Error Accumulation If you round to 2 decimal places the rounding errors is ………? If you then multiply the result by 1000 the rounding error becomes ……?

128 Overflow Using 8bit integer perform the following calculation Represent the answer as binary

129 Overflow Convert the following numbers... Add the following numbers together and then convert the answer... Is this right?

130 Summary There are issues with binary representation Good programming languages will warn you of this... Needs to be handled by the developer.


Download ppt "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."

Similar presentations


Ads by Google