How to swap the first two bits of a number in Python

1 Answer

0 votes
n = 162
     
print(bin(n))
   
n ^= (1 << 0);
n ^= (1 << 1);
 
print(bin(n))
      
      
       
'''
run:
   
0b10100010
0b10100001
   
'''

 



answered Mar 18, 2019 by avibootz

Related questions

1 answer 190 views
1 answer 195 views
1 answer 196 views
1 answer 191 views
1 answer 194 views
1 answer 207 views
...