how to work with other base numbers in java?

前端 未结 5 1987
广开言路
广开言路 2021-01-05 11:13

Guys if the int c=10001; which is a binary value.If i want to process it like multiplying it by 10 how to do that?

5条回答
  •  无人及你
    2021-01-05 11:51

    You can specify it as int c = 0x11 (consider 10001 is 0001 0001, which is 11 in hex)

    public static void main(String[] args) throws Exception {
        int c = 0x11; // 10001
        int d = 10; // ten decimal
        int d = 0x2; // ten binary 0010 - see table below
        System.out.println(c);
        System.out.println(c*d);
      System.out.println(c*e);  
    }
    

    binary-decimal conversion

    • 0 0000
    • 1 0001
    • 2 0010
    • 3 0011
    • 4 0100
    • 5 0101
    • 6 0110
    • 7 0111
    • 8 1000
    • 9 1001
    • A 1010
    • B 1011
    • C 1100
    • D 1101
    • E 1110
    • F 1111

提交回复
热议问题