Example Use of Binary Operators in Java

public class JavaBinary
{
    public static void main(String args[])
    {
       int num1 = 255;
       int num2 = 12;
       int result;

       result = num1 & num2;
       System.out.println("num1 AND num2 = " + Integer.toBinaryString(result) +
                            " = (in hex) " + Integer.toHexString(result));
       result = num1 | num2;
       System.out.println("num1 OR num2 = " + Integer.toBinaryString(result));
       result = ~num1;
       System.out.println("NOT num1 = " + Integer.toBinaryString(result));
     }
}