Suppose you want to get the numerical value of the last two binary digits, we can use a mask.
public static void main(String[] args) {
int n = 0b1110;
int mask = 0b11;
System.out.println(n & mask);
}
What the code does is take a number, in this case, 0b1110and do it andwith the mask installed 0b11.
0b , java, .
, :
Integer.toBinaryString(n & mask)