本文介绍了如何从msb开始获取特定位置的位值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以前从未在Java中使用过位,因此问题如下:我有
I never worked with bits in Java before, so the question is the following:I have
byte a=254;
如何从msb位置开始从该字节中获取位?
How to get a bits from this byte, starting from msb position?
If position == 0 it returns 1
If position == 7 it returns 0
提前谢谢
推荐答案
int getBitFromMSB(byte x,int position){
return (x >>> (7 - position)) & 1;
}
这篇关于如何从msb开始获取特定位置的位值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!