xxxxxxxxxx
import java.util.*;
public class Swapping {
public static void main(String[] args)
{
byte a=9, b=12; // Instead of wasting the bit we can store the bitvalue in same byte
byte c;
c=(byte)(a<<4); // we want to store the byte thats why byte typecasting //4 bit for 9 , 4 bit for 12 so total 1 byte will take to store
c=(byte)(c|b);
System.out.println((c&0b11110000)>>4); // bitwise masking
System.out.println(c&0b00001111);
}
}