[英]What does hibyte = Value >> 8 meaning?
I am using C for developing my program and I found out from an example code 我正在使用C开发程序,并从示例代码中找到了
unHiByte = unVal >> 8;
What does this mean?? 这是什么意思?? If
unVal = 250
. 如果
unVal = 250
。 What could be the value for unHiByte ?? unHiByte的值是什么 ?
I am really confused with this..Please Help.. 我对此真的感到困惑。请帮助。
Thanks in advance.. 提前致谢..
">>" in programming is a bitwise operation. 编程中的“ >>”是按位运算。 The operation >> means shift right operation.
操作>>表示右移操作。 So unVal >> 8 means shift right unVal by 8 bits.
因此,unVal >> 8表示将unVal右移8位。 shifting the bits to the right can be interpreted as dividing the value by 2.
将位右移可以解释为将值除以2。
Hence, unHiByte = unval >> 8 means unHiByte = unVal/(2^8) (divide unVal by 2 eight times) 因此,unHiByte = unval >> 8表示unHiByte = unVal /(2 ^ 8)(将unVal除以2八次)
Without going into the shift operator itself (since that is answered already), here the assumption is that unVal is a two byte variable with a high byte (the upper 8 bits) and a low byte (the lower 8 bits). 无需进入移位运算符本身(因为已经回答了),这里的假设是unVal是一个两个字节的变量,具有一个高字节(高8位)和一个低字节(低8位)。 The intent is to obtain the value produced by ONLY the upper 8 bits and discarding the lower bits.
目的是获得仅由高8位并舍弃低位所产生的值。
The shift operator though should easily be learned via any book / tutorial and perhaps was the reason some one down voted the question. 移位运算符虽然可以通过任何书籍/教程轻松学习,但这也许是某个人否决了该问题的原因。
The >>
is a bitwise right shift . >>
是按位右移 。
It operates on bits. 它按位操作。 With
unHiByte = unVal >> 8;
用
unHiByte = unVal >> 8;
When unVal=250
. 当
unVal=250
。
Its binary form is 11111010
它的二进制形式是
11111010
Right shift means to shift the bits to the right. 右移表示将位向右移。 So when you shift
1111 1010
, 8 digits to right you get 0000 0000
. 因此,当您将
1111 1010
右移8位时,您将得到0000 0000
。
Note: You can easily determine the right shift operation result by dividing the number to the left of >>
by 2^(number to right of >>
) 注意:您可以通过将
>>
左边的数字除以2 ^( >>
右边的数字)来轻松确定右移运算结果。
So, 250/2
8 = 0
因此,
250/2
8 = 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.