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?
Asked
Active
Viewed 61 times
0
-
What exactly are you trying to achieve? And what have you tried so far? – Mureinik Jan 18 '16 at 09:19
-
lets say I have byte b=01000000 I need for upper 4 bits value only 0x40(64 in decimal) and for lower bits my value must be evaluated to 0. – Priya Kothari Jan 18 '16 at 09:25
1 Answers
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