Bit masking in Python

前端 未结 4 887
臣服心动
臣服心动 2021-02-14 04:11

I have a byte (from some other vendor) where the potential bit masks are as follows:

value1 = 0x01 value2 = 0x02 value3 = 0x03 value4 = 0x04 value5 = 0x05 value6 = 0x06

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-14 04:57

    You don't need the other two functions:

    def parse_byte(byte):
        value7_set = byte & value7 == value7
        value8_set = byte & value8 == value8
        base_value =  byte & 7
        return value7_set,value8_set,base_value
    

提交回复
热议问题