xor using python code example

Example 1: write a program to input a number and display its double and half values using shift operator in python

# Write a program to input a number and display its Double and Half values using SHIFT operator.

print("Hi \nThis is a basic calculator \nwhich doubles or divides into half the value entered in it")
i = int(input("pls enter your number:\n"))
print("what do you want to do? \nwarning: \nenter only the alphabet of the option and no symbols.")
print("you can enter both the options alphabet to get both the values")
print("This program gives and takes only integer value of double, half and input")
opt = input("options:- \na.double\nb.half\n")
if opt == "a":
    j = i << 1
    print("double", j)
elif opt == "b":
    k = i >> 1
    print("half:", k)
elif opt == "ab" or opt == "a b" or opt == "ba" or opt == "b a" or opt == " ab" or opt == "ab " or opt == " ab " or opt == " a b" or opt == "a b " or opt == " a b ":
    j = i << 1
    k = i >> 1
    print("number:", i)
    print("double:", j)
    print("half:", k)
else:
    print("inputs are wrong")
    exit()

Example 2: xor in python

#!/usr/bin/python

a = 60            # 60 = 0011 1100 
b = 13            # 13 = 0000 1101 
c = 0

c = a & b;        # 12 = 0000 1100
print "Line 1 - Value of c is ", c

c = a | b;        # 61 = 0011 1101 
print "Line 2 - Value of c is ", c

c = a ^ b;        # 49 = 0011 0001
print "Line 3 - Value of c is ", c

c = ~a;           # -61 = 1100 0011
print "Line 4 - Value of c is ", c

c = a << 2;       # 240 = 1111 0000
print "Line 5 - Value of c is ", c

c = a >> 2;       # 15 = 0000 1111
print "Line 6 - Value of c is ", c