Java (8, 16 conversion to binary decimal 10) based on the binary string conversion

// 8, 16 hexadecimal to decimal conversion

Integer b = Integer.parseInt ( "1001" , 2); // 2 decimal binary switch
Integer o = Integer.parseInt ( "12" , 8); // 8 -ary transfected decimal
Integer h = Integer .parseInt ( "123ABC", 16) ; // 16 hex 10 hex rpm

or

Integer b = Integer.valueOf ( "1001" , 2); // 2 decimal binary switch
Integer o = Integer.valueOf ( "12" , 8); // 8 -ary transfected decimal
Integer h = Integer .valueOf ( "123ABC", 16) ; // 16 hex 10 hex rpm

or

// BigInteger is based on binary conversion

BigInteger b = new BigInteger ( "1001 ", 2); // 2 decimal binary switch
BigInteger o = new BigInteger ( "12 ", 8); // 8 -ary rotation band 10
BigInteger h = new BigInteger ( "123ABC", 16); // 16 decimal turn hex

 

// 10 decimal turn 8, 16 hex

String tb = Integer.toBinaryString (b); // 10 transfer binary decimal
String to = Integer.toOctalString (o); // 10 decimal turn octal
String th = Integer.toHexString (h); // decimal turn hex

or

String tb = Integer.toString (b, 2 ); // 10 transfer binary decimal
String to = Integer.toString (o, 8 ); // 10 decimal turn octal
String th = Integer.toString (h , 16); // switch 10 hex 16 hex

or

// BigInteger is based on binary conversion

 

BigInteger b = new BigInteger ( "1001 ", 2); // 2 decimal binary switch
BigInteger o = new BigInteger ( "12 ", 8); // 8 -ary rotation band 10
BigInteger h = new BigInteger ( "123ABC", 16); // 16 hex 10 hex transfected
String tb = b.toString (2); // 10 transfer binary decimal
String to = o.toString (8); // 10 hex turn octal
String th = h.toString (16); // 10 hex 16 hex rpm

Guess you like

Origin www.cnblogs.com/clgmxxh/p/12203815.html