问题
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