DeaD_EyE icon

inverse bytes (LSB <-> MSB)

DeaD_EyE | PRO | 08/02/22 08:38:04 AM UTC | 0 ⭐ | 1758 👁️ | Never ⏰ | []
Python |

340 B

|

None

|

0 👍

/

0 👎

def inverse(value: int):
    mask = 0xFF
    width = 8
    result = 0
    bit = 1
    rev = 7
 
    while value:
        for shift in range(width):
            if value & mask & bit << shift:
                result |= bit << (rev - shift)
 
        value >>= width
 
        if value:
            result <<= width
 
    return result
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎