10-》2
  private void pBinInt(String s, int i) {
    System.out.println(
      s + ", int: " + i + ", binary: ");
    System.out.print("   ");
    for(int j = 31; j >=0; j--)   //代码A
    {
      if(((1 << j) &  i) != 0)
        System.out.print("1");
      else
        System.out.print("0");    //代码B
      System.out.println("1<<j="+(1 << j));
    }
    System.out.println();       
  }

解决方案 »

  1.   

    int i = 10;
    String s1  = Integer.toBinaryString(i);
    String s2  = Integer.toHexString(i);
    String s3  = Integer.toOctalString(i);
      

  2.   

    // 以其他数字为基底的整数转换常式
    byte b = Byte.parseByte("1011", 2); // 二进位的 1011 , 在十进位中则是 11
    short sh = Short.parseShort("ff", 16); // 十六进位的 ff , 在十进位中为 255 // valueOf() 方法可以处理任意的基底(base)
    int i = Integer.valueOf("egg", 17).intValue(); // 以 17 为基底 // decode() 方法可以处理八进位、十进位或十六进位
    // 要看该字串前面的数字为何
    short sh = Short.decode("0377").byteValue(); // 以 0 开头表示是八进位
    int i = Integer.decode("0xff").shortValue(); // 以 0x 开头表示是十六进位
    long l = Long.decode("255").intValue(); // 其他的数字则表示是十进位 // 能将数字转换为字串的 Integer 类别
    String decimal = Integer.toString(42);
    String binary = Integer.toBinaryString(42);
    String octal = Integer.toOctalString(42);
    String hex = Integer.toHexString(42);
    String base36 = Integer.toString(42, 36);