[英]Checking byte with bitwise operators
I could use this: 我可以用这个:
unsigned long alpha = 140 | 130 << 8 | 255 << 16;
to set 140
to the first byte of alpha
, 130
to the second and 255
as 3rd. 将140
设置为alpha
的第一个字节,将130
设置为第二个,并将255
为3rd。 How do I do the opposite (ie checking a specific byte of alpha
) ? 我该如何做相反的操作(即检查alpha
的特定字节)?
alpha & 255 // works for the first byte
alpha >> 16; // works for the 3rd byte
Shift the value x bits to the right and then use AND to restrict the number of bits you use. 将值x右移,然后使用AND限制使用的位数。 ie: (n >> 8) & 0xff
or (n >> 16) & 0xff
. 即: (n >> 8) & 0xff
或(n >> 16) & 0xff
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.