Module 1 Class Presentation CS5002
Module 1 Class Presentation CS5002
Discrete Structures
• Please put away / silence your phone, and have only GoogleDoc, this Powerpoint,
and/or Teams running on your laptop
• Be sure your name card is in place (your instructor will always be fooled)
• Then, following the Study Guide 1, you had some stuff to study
• And then you should have done your Quiz 1 yourself
• It was due at the start of class
• Please submit Problem Set 0 and Quiz 1 now if you did not already
• In the future they are always due before class starts
Review of Problem Set 0
• Magic Squares
• Guess My Number
• https://www.mathsisfun.com/games/guess_number.html
• Perfect Squares
Quiz 1 In Groups
• Do you have any questions about the study materials and Quiz 1?
• How useful were the additional video links? How about the additional tutorial links?
• Now let’s arrange into groups and each group do the same Quiz 1
• Put your answers into today’s GoogleDoc
• Today’s Groups:
How much fits into a 64b word? 264 = 24+60 = 24 x 260 = 16 with 18 zeros
Important Uses of Hexadecimal
Numbers
• Hex is used to represent binary numbers
• Computers do a lot with “bytes” = 8 bits = 2 nibbles = 2 hex digits
• 01101011 = 0110 1011 = 0x6B note the “0x” prefix commonly
used
0 7 8 15
Interpreting bits as unsigned number
0 7 -8 -1
Overflow occurs when the value of an arithmetic result is outside the range of
numbers that can be represented (notice the sign bits!)
Carry occurs when there are not enough bits to represent the answer
An Overflow Example In The C
Language
• When you add two positive numbers whose result is too large to represent,
the result has a sign bit of 1 -- overflow!
• When you add two negative numbers whose result is too small to represent,
the result has a sign bit of 0 -- overflow!
• Can you get overflow when you add a positive and a negative number?
• You will investigate this in Problem Set 1
Activity For Today – The Game of “Nim”
Our last class activity for today … the game of Nim
• https://www.goobix.com/games/nim/
• See if you can beat the computer in 5 minutes of play
XOR Addition
XOR (“Exclusive OR”) is an operation on bits
• A OR B means “A is 1” or “B is 1” or “both are 1”
• A XOR B means “A is 1” or “B is 1” but “not both are 1”
• So it’s like OR but excludes the case that both are 1
• It also means “not equal” … A and B have different values
• When you have multiple bits, XOR means that an odd number are 1
• Mathematicians write it like this: A B
• Computer programmers write it like this: A ^ B
We Can Use XOR To Win The Nim Game
We calculate the “NIM SUM” for the current game
• Write the number in each pile, using binary numbers
• Add them up using XOR for each column
• The result is the NIM SUM
If the piles are all empty, the last person just won and the Nim Sum is 0
Otherwise, if it’s your turn and the Nim Sum is not 0, make it 0
But if it’s your turn and the Nim Sum is already 0, you might be a loser!
• Study Guide 2 is what you need to learn for the next class
• Quiz 2 is based on the study materials; due in Canvas before next class