
class Main
{
  public static void main (String[] args) throws java.lang.Exception
  {
      long start = System.nanoTime();
      for (int i = 0; i < 1E6; i++) {
          methodA((byte) i);
      }
      System.out.println("Method A took: " + (System.nanoTime() - start));
      start = System.nanoTime();
      for (int i = 0; i < 1E6; i++) {
          methodB((byte) i);
      }
      System.out.println("Method B took: " + (System.nanoTime() - start));
  }
  
  public static String methodA(byte b) { // with String methods
      return String.format("%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');
  }
  
  public static String methodB(byte b) { // with bitwise
      return Integer.toBinaryString((b & 0xFF) + 0x100).substring(1);
  }
}