#(&,|,^,<<,>>,-) #print(), bin() x = 5 print('X: ',bin(x)) y = 6 print('Y: ',bin(y)) print('operation <<') print(bin(x)) x = x<<3 #shift to the left by n bits print(bin(x)) x = x>>3 #shifts to the right by n bits print(bin(x)) print('\n') print('Operation |') print(bin(x|y)) #bitwise "or" (forms 3d integer, by bitwise comparison of 2 integers by the rules of "OR") print('\n') print('Operation &') print(bin(x&y)) #bitwise "and" (forms 3d integer, by bitwise comparison of 2 integers by the rules of "AND") print('\n') print('XOR ^') print(bin(x^y)) #bitwise "exclusive or" (forms 3d integer, by bitwise comparison of 2 integers by the rules of "XOR") print('\n') print('inversion ~') print(bin(~x)) #inverse bites (forms new integer, by inversing of integer "x")
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question