Java base for the conversion
Blue Bridge Cup a few exercises are related to binary conversion, write a little blog here about the record.
Here the data does not exceed the range of int , for example, the methods used are all Integer class.
Other binary decimal turn
With the Integer.parseInt (a, b) method, a binary representation of another string, b is the radix, thus converted to a decimal out.
int a = Integer.parseInt(StringOfNumber, radix);
Decimal turn the other band
With Integer.toString (i, radix) method, i denotes a decimal number, radix showing another will be converted to binary.
String s = Integer.toString(i, radix);
There are some special methods, the corresponding特殊的进制
//对应十进制转二进制
Integer.toBinaryString(i);//
//对应十进制转八进制
Integer.toOctalString(i);//
//对应十进制转十六进制
Integer.toHexString(i);//
Other band turn the other band
Through intermediate conversion to decimal.
Note: In the title should pay attention to the range of data, it is possible to convert a decimal is too large, this time to use a larger scale, such as Long