Operator “|” usage is c raspberry pi

走远了吗. 提交于 2020-01-17 17:57:39

问题


I am using raspberry pi to read a gyroscopic data. Am new to it but so far I understand everything that I am basing my code from besides the use of "|" in it. When looking it up it says its "bitwise OR" operator but in my situation it doesnt make sense, than again I don't understand the explanation on Wikipedia.

The line that uses it looks as follows

readBlock(0x80 | OUT_X_L_G, sizeof(block), block);

readBlock is user defined function as follows.

readBlock(uint8_t command, uint8_t size, uint8_t *data) {
int result = i2c_smbus_read_i2c_block_data(file, command, size, data);
}

回答1:


The expression 0x80 | OUT_X_L_G is returning a value of OUT_X_L_G with a bit number 7 set:

OUT_X_L_G = xxxx xxxx
  bitwise or
0x80      = 1000 0000
---------------------
result    = 1xxx xxxx

The logic behind the whole function call should be determined by the context you are not providing.



来源:https://stackoverflow.com/questions/34861462/operator-usage-is-c-raspberry-pi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!