class BitManiPaulation:
    __slots__ = ['__num']
    def __init__(self,num:int):
        self.__num = num


    def get_bit(self,postistion):
        mask = 1<<postistion

        return bool(self.__num & mask)

    def set_bit(self,postion:int,value:bool):
        mask = 1<<postion
        if value:
            self.__num |=mask
        else:
            self.__num &=mask

    @property
    def get_bits(self):
        bits=[]
        while self.__num:
            bits.append(self.__num & 1)
            self.__num>>=1
            print(self.__num)
        return bits[::-1]

    @property
    def bits(self):
        bin_array=bin(self.__num)[2:].zfill(16)
        a=bin_array[0:4]
        b=bin_array[4:8]
        c=bin_array[8:12]
        d=bin_array[12:16]
        return f'{self.__num}的二进制数为: {a}_{b}_{c}_{d}'




a=BitManiPaulation(12)
print(a.bits)
print(a.get_bit(4))
print(a.bits)

06-10 01:19