1

Can we have in Java one byte whose upper 4 bits represent values like 0x40/0x80 and lower 4 bits representing values like 0,1,2,3.If yes then how do we retrieve values out of that on byte?Any help is greatly appreciated.

1

2 Answers 2

1

A simple example is probably easier than using words to describe it.

byte data = 0x74;
int high4 = (data >> 4) & 0xf;
int low4 = data & 0xf;
Sign up to request clarification or add additional context in comments.

Comments

1

You can create wrapper class for byte or int with methods that fidget bits.

int first4bits = (byteContainer >> 4) & 0xF;
int last4bits = byteContainer & 0xF;

The problem is that such actions are inappropriate in Java.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.