Reputation: 47
Say you are having a byte of pattern:
byte b = 0x%1;
How to tell when a byte does have certain values on the "2nd position" - in place of %
?
In this example 1, no matter what the 1st position holds.
Upvotes: 1
Views: 259
Reputation: 43504
Use a mask bits to get the last 8 bits:
int last8bits = b & 0xF;
Edit: You should read up on bitwise operations.
Full example:
public static void main(String[] args) {
byte b = (byte) 0xA1;
int last8bits = b & 0xF;
if (last8bits == 0x01)
System.out.println("\"matches\"");
}
Upvotes: 1