Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #!/usr/bin/python3
  2. #coding=utf-8
  3. #save file : bitwise_operators_example.py
  4.  
  5.  
  6. a = 60 # 60 = 0011 1100
  7. b = 13 # 13 = 0000 1101
  8. print ('a=',a,':',bin(a),'b=',b,':',bin(b))
  9. c = 0
  10.  
  11. c = a & b; # 12 = 0000 1100
  12. print ("result of AND is ", c,':',bin(c))
  13.  
  14. c = a | b; # 61 = 0011 1101
  15. print ("result of OR is ", c,':',bin(c))
  16.  
  17. c = a ^ b; # 49 = 0011 0001
  18. print ("result of EXOR is ", c,':',bin(c))
  19.  
  20. c = ~a; # -61 = 1100 0011
  21. print ("result of COMPLEMENT is ", c,':',bin(c))
  22.  
  23. c = a << 2; # 240 = 1111 0000
  24. print ("result of LEFT SHIFT is ", c,':',bin(c))
  25.  
  26. c = a >> 2; # 15 = 0000 1111
  27. print ("result of RIGHT SHIFT is ", c,':',bin(c))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement