from typing import Tuple


class Bit:
    """
    This class contains some bit-related utility function.
    """
    _REVERSE8_LOOKUP: Tuple[int, ...] = (
        0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE, 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF
    )

    @staticmethod
    def reverse_8(n: int) -> int:
        """
        Reverses bits of a 8 bits integer

        Benchmark (100 iterations):

        * MEAN TIME: 332.0 ns
        * MAX TIME: 1.7 µs
        * MIN TIME: 300 ns

        :param n: The 8 bits integer to reverse
        :returns: A reversed 8 bits integer
        """
        return (Bit._REVERSE8_LOOKUP[n & 0b1111] << 4) | Bit._REVERSE8_LOOKUP[n >> 4]

    @staticmethod
    def reverse_64(n: int) -> int:
        """
        Reverses bits of a 64 bits integer

        Benchmark (100 iterations):

        * MEAN TIME: 809.0 ns
        * MAX TIME: 3.2 µs
        * MIN TIME: 700 ns

        :param n: The 64 bits integer to reverse
        :returns: A reversed 64 bits integer
        """
        n = ((n & 0x55555555) << 1) | ((n & 0xAAAAAAAA) >> 1)
        n = ((n & 0x33333333) << 2) | ((n & 0xCCCCCCCC) >> 2)
        n = ((n & 0x0F0F0F0F) << 4) | ((n & 0xF0F0F0F0) >> 4)
        n = ((n & 0x00FF00FF) << 8) | ((n & 0xFF00FF00) >> 8)
        n = ((n & 0x0000FFFF) << 16) | ((n & 0xFFFF0000) >> 16)
        return n

    @staticmethod
    def reverse_color(n: int) -> int:
        """
        Swaps a RGB to a BGR vice-versa

        :param n: The color to reverse
        :returns: The reversed color
        """
        c1: int = (n >> 16) & 0xFF
        c2: int = (n >> 8) & 0xFF
        c3: int = n & 0xFF

        return (c3 << 16) | (c2 << 8) | c1


if __name__ == '__main__':
    a = 0b00000000000000000000000000001111
    assert Bit.reverse_64(a) == 0b11110000000000000000000000000000
    a = 0b01010101
    assert Bit.reverse_8(a) == 0b10101010

    # nn = 0x0000A0
    # print('Expected = ', 0xA00000, Bit.reverse_color(nn))

from typing import Tuple


class Bit:
    """
    This class contains some bit-related utility function.
    """
    _REVERSE8_LOOKUP: Tuple[int, ...] = (
        0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE, 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF
    )

    @staticmethod
    def reverse_8(n: int) -> int:
        """
        Reverses bits of a 8 bits integer

        Benchmark (100 iterations):

        * MEAN TIME: 332.0 ns
        * MAX TIME: 1.7 µs
        * MIN TIME: 300 ns

        :param n: The 8 bits integer to reverse
        :returns: A reversed 8 bits integer
        """
        return (Bit._REVERSE8_LOOKUP[n & 0b1111] << 4) | Bit._REVERSE8_LOOKUP[n >> 4]

    @staticmethod
    def reverse_64(n: int) -> int:
        """
        Reverses bits of a 64 bits integer

        Benchmark (100 iterations):

        * MEAN TIME: 809.0 ns
        * MAX TIME: 3.2 µs
        * MIN TIME: 700 ns

        :param n: The 64 bits integer to reverse
        :returns: A reversed 64 bits integer
        """
        n = ((n & 0x55555555) << 1) | ((n & 0xAAAAAAAA) >> 1)
        n = ((n & 0x33333333) << 2) | ((n & 0xCCCCCCCC) >> 2)
        n = ((n & 0x0F0F0F0F) << 4) | ((n & 0xF0F0F0F0) >> 4)
        n = ((n & 0x00FF00FF) << 8) | ((n & 0xFF00FF00) >> 8)
        n = ((n & 0x0000FFFF) << 16) | ((n & 0xFFFF0000) >> 16)
        return n

    @staticmethod
    def reverse_color(n: int) -> int:
        """
        Swaps a RGB to a BGR vice-versa

        :param n: The color to reverse
        :returns: The reversed color
        """
        c1: int = (n >> 16) & 0xFF
        c2: int = (n >> 8) & 0xFF
        c3: int = n & 0xFF

        return (c3 << 16) | (c2 << 8) | c1


if __name__ == '__main__':
    a = 0b00000000000000000000000000001111
    assert Bit.reverse_64(a) == 0b11110000000000000000000000000000
    a = 0b01010101
    assert Bit.reverse_8(a) == 0b10101010

    # nn = 0x0000A0
    # print('Expected = ', 0xA00000, Bit.reverse_color(nn))

This class contains some bit-related utility function. Reverses bits of a 8 bits integer          Benchmark (100 iterations):          * MEAN TIME: 332.0 ns         * MAX TIME: 1.7 µs         * MIN TIME: 300 ns          :param n: The 8 bits integer to reverse         :returns: A reversed 8 bits integer Reverses bits of a 64 bits integer          Benchmark (100 iterations):          * MEAN TIME: 809.0 ns         * MAX TIME: 3.2 µs         * MIN TIME: 700 ns          :param n: The 64 bits integer to reverse         :returns: A reversed 64 bits integer Swaps a RGB to a BGR vice-versa          :param n: The color to reverse         :returns: The reversed color # nn = 0x0000A0 # print('Expected = ', 0xA00000, Bit.reverse_color(nn))