Basic bit operations in Python:
#!/usr/bin/python
a = 60 # 60 = 0011 1100
b = 13 # 13 = 0000 1101
c = 0
print "a = ", (bin(a)[2:]);
print "b = ", (bin(b)[2:]);
c = a & b; # 12 = 0000 1100
print "a & b = ", (bin(c)[2:]);
c = a | b; # 61 = 0011 1101
print "a | b = ", (bin(c)[2:]);
c = a ^ b; # 49 = 0011 0001
print "a ^ b = ", (bin(c)[2:]);
c = ~a; # -61 = 1100 0011
print "~a = ", (bin(c)[2:]);
c = a << 2; # 240 = 1111 0000
print "a <> 2; # 15 = 0000 1111
print "a >> 2 = ", (bin(c)[2:]);
Result:
An interesting link about bit operation algorithm implementation in Python is here.
Brooks 11:35 am on June 30, 2017 Permalink |
magnificent issues altogether, you just gained a emblem new reader. What may you recommend about your publish that you made some days ago? Any certain?
restaurant frankfurt oder 1:39 pm on June 30, 2017 Permalink |
Grüße! Sehr hilfreiche Beratung in diesem Beitrag! Es sind die kleinen Veränderungen, die die größten Veränderungen bewirken werden. Danke für das Teilen!
anexo monografia 2:52 am on August 31, 2017 Permalink |
Heya i’m for the primary tikme here. I came across this board and I in finding It really helpful & it helped me out
a lot. I hope to offer one thing again and aid others like you helped me.
Sarjoni 1:39 pm on January 13, 2019 Permalink |
Thank for share,