You can convert a decimal to binary using three different methods as shown below:

  int i = 42;
   String hexstr = Integer.toString(i, 16);

   or
   
   String hexstr = Integer.toHexString(i);

   or (with leading zeroes and uppercase)
   
   public class Hex {
     public static void main(String args[]){
       int i = 42;
       System.out.print
         (Integer.toHexString( 0x10000 | i).substring(1).toUpperCase());
      }
     }