How to get a bit value on particular position starting from msb?

后端 未结 1 1666
感动是毒
感动是毒 2021-01-14 05:20

I never worked with bits in Java before, so the question is the following: I have

byte a=254;

How to get a bits from this byte, starting

相关标签:
1条回答
  • 2021-01-14 06:19
    int getBitFromMSB(byte x,int position){
        return (x >>> (7 - position)) & 1;
    }
    
    0 讨论(0)
提交回复
热议问题