Advertisement
DeaD_EyE

inverse bytes (LSB <-> MSB)

Aug 2nd, 2022
1,147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. def inverse(value: int):
  2.     mask = 0xFF
  3.     width = 8
  4.     result = 0
  5.     bit = 1
  6.     rev = 7
  7.  
  8.     while value:
  9.         for shift in range(width):
  10.             if value & mask & bit << shift:
  11.                 result |= bit << (rev - shift)
  12.  
  13.         value >>= width
  14.  
  15.         if value:
  16.             result <<= width
  17.  
  18.     return result
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement