简体   繁体   中英

1 byte that represents different values in java

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?

Bit masking. To get the upper 4 bits:

Upper=byte&0xF0

To get the first

First=byte&0x01

And so on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM