为什么在写到I2C之前要对值进行移位?

问题描述 投票:0回答:1

最近买了arducam的PTZ-Camera控制器,在github上发现了一种APIController软件(https:/github.comArduCAMPTZ-Camera-Controller。). (0x4650 & 0xFF00) >> 8))

def read(self, I2C_address, register_address):
    value = self.bus.read_word_data(I2C_address, register_address)
    value = ((value & 0x00FF) << 8) | ((value & 0xFF00) >> 8)        #This one
    return value

def write(self, I2C_address, register_address, value):
    if value < 0:
        value = 0
    value = ((value & 0x00FF) << 8) | ((value & 0xFF00) >> 8)         #And this one
    return self.bus.write_word_data(I2C_address, register_address, value)

Which should equal 2400, by my estimation. Fairly close to 2317. However:

Why would they do this, instead of just having the input span from 0 to 2317?

I recently bought the PTZ-Camera-controller from arducam, and found a kind of API 我试着理解python程序,但有一行在程序中出现了好几次,让我很困惑。
python bit-shift i2c
1个回答
0
投票

看起来那是在16位整数中翻转两个字节的顺序.那可能是为了从大恩迪安转换到小恩迪安,两种不同的整数表示方式。我认为控制器使用大恩迪安,PC使用小恩迪安。(https:/en.wikipedia.orgwikiEndianness。)

© www.soinside.com 2019 - 2024. All rights reserved.