0

I have one byte that contains Upper 4 bits are a bitmap for system status like 0x40,0x80 and Lower 4 bits values like 0,1,2,3. I do not know to parse them.Can someone help me.can I have anything like this?how byte will look like???will it be byte b=(byte)0x80?

1 Answers1

0

Bit masking. To get the upper 4 bits:

Upper=byte&0xF0

To get the first

First=byte&0x01

And so on.

ddacot
  • 1,212
  • 3
  • 14
  • 40
  • byte b=(byte)00100010; int Upper= b & 0xF0; int First= b & 0x01; System.out.println(Integer.toBinaryString(First));It bring 0 as output for Upper . – Priya Kothari Jan 18 '16 at 09:30