# 02-shift-ops.py
# Topic: Left Shift Doubles the Number, Divide Without /
input("Left shift doubles, right shift halves. Press Enter ")
print(" 3 << 1 =", 3 << 1, " 12 >> 1 =", 12 >> 1)
print(" 3 << 2 =", 3 << 2, " 12 >> 2 =", 12 >> 2)
n = int(input("Enter a number (try 5 or 8): "))
guess = input("What is " + str(n) + " << 2? ")
input("Left shift by 2 multiplies by 4. Press Enter ")
print(" ", n, "<< 2 =", n << 2, " your guess:", guess)
# 03-sign-detect.py
# Topic: XOR for Sign Detection
input("XOR sign detection - n ^ m < 0 means different signs. Press Enter ")
print(" 4 ^ 2 =", 4 ^ 2, " same signs positive")
print(" 4 ^ -2 =", 4 ^ -2, " different signs negative")
n = int(input("Enter a number (try 5 or -3): "))
guess = input("Will " + str(n) + " ^ -8 be positive or negative? ")
input("XOR is negative when signs differ. Press Enter ")
print(" ", n, "^ -8 =", n ^ -8, " your guess:", guess)
To embed this project on your website, copy the following code and paste it into your website's HTML: