avail_data[0] = (avail_bits >> 8) & 0xFF; avail_data[1] = avail_bits & 0xFF;什么意思
时间: 2024-05-25 17:16:39 浏览: 132
& 0xFF
avail_data[1] = avail_bits & 0xFF
The above code takes the integer variable "avail_bits", which is assumed to be 16 bits long, and splits it into two separate bytes.
The first byte is obtained by right shifting the bits in "avail_bits" by 8 places, which essentially discards the lower 8 bits and retains the upper 8 bits. The result is then bitwise ANDed with 0xFF, which sets all bits except the lower 8 bits to 0. This ensures that the first byte contains only the upper 8 bits of "avail_bits".
The second byte is obtained by simply bitwise ANDing "avail_bits" with 0xFF, which sets all bits except the lower 8 bits to 0. This ensures that the second byte contains only the lower 8 bits of "avail_bits".
The resulting bytes are stored in the array "avail_data", with the first byte at index 0 and the second byte at index 1.
阅读全文