How to swap the first 4 bits of a number with the last 4 bits in Python

1 Answer

0 votes
n = 92
    
print(bin(n))
  
n = ((n & 0xf0) >> 4) | ((n & 0x0f) << 4)

print(bin(n))
     
     
      
'''
run:
  
0b1011100
0b11000101
  
'''

 



answered Mar 14, 2019 by avibootz

Related questions

1 answer 208 views
1 answer 197 views
1 answer 202 views
1 answer 196 views
1 answer 223 views
1 answer 189 views
...