## 进制之间的转换

int i = 'a';
String iBin = Integer.toBinaryString(i);//二进制
String iHex = Integer.toHexString(i);//十六进制
String iOct = Integer.toOctalString(i);//八进制
String iWoKao = Integer.toString(i,3);//三进制或任何你想要的35进制以下的进制

DEC[集]java中进行二进制，八进制，十六进制，十进制间进行相互转换

Integer.toHexString(int i)

Integer.toOctalString(int i)

Integer.toBinaryString(int i)

Integer.valueOf("FFFF",16).toString()

Integer.valueOf("876",8).toString()

Integer.valueOf("0101",2).toString()

java.lang.Integer类

examples from jdk:
parseInt("0", 10) returns 0
parseInt("473", 10) returns 473
parseInt("-0", 10) returns 0
parseInt("-FF", 16) returns -255
parseInt("1100110", 2) returns 102
parseInt("2147483647", 10) returns 2147483647
parseInt("-2147483648", 10) returns -2147483648
parseInt("2147483648", 10) throws a NumberFormatException
parseInt("99", 8) throws a NumberFormatException
parseInt("Kona", 10) throws a NumberFormatException
parseInt("Kona", 27) returns 411787

Integer.toBinaryString
Integer.toOctalString
Integer.toHexString

public class Test{
public static void main(String args[]){
int i=100;
String binStr=Integer.toBinaryString(i);
String otcStr=Integer.toOctalString(i);
String hexStr=Integer.toHexString(i);
System.out.println(binStr);

public class TestStringFormat {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("usage: java TestStringFormat <a number>");
System.exit(0);
}
Integer factor = Integer.valueOf(args[0]);
String s;
s = String.format("%d", factor);
System.out.println(s);
s = String.format("%x", factor);
System.out.println(s);
s = String.format("%o", factor);
System.out.println(s);
}
}

String s = String.valueOf( value); // 其中 value 为任意一种数字类型。

String s = "169";
byte b = Byte.parseByte( s );
short t = Short.parseShort( s );
int i = Integer.parseInt( s );
long l = Long.parseLong( s );
Float f = Float.parseFloat( s );
Double d = Double.parseDouble( s );

byte b = 169;
Byte bo = new Byte( b );
b = bo.byteValue();
short t = 169;
Short to = new Short( t );
t = to.shortValue();
int i = 169;
b = bo.byteValue();
short t = 169;
Short to = new Short( t );
t = to.shortValue();
int i = 169;
Integer io = new Integer( i );
i = io.intValue();
long l = 169;
Long lo = new Long( l );
l = lo.longValue();
float f = 169f;
Float fo = new Float( f );
f = fo.floatValue();
double d = 169f;
Double dObj = new Double( d );
d = dObj.doubleValue();

posted on 2008-08-10 15:54 hobo 阅读(464) 评论(0)  编辑 收藏 引用 所属分类: ACM/ICPC_java用法

 < 2008年8月 >
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

• 随笔 - 49
• 文章 - 3
• 评论 - 58
• 引用 - 0

•