-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedixConvert.java
More file actions
43 lines (35 loc) · 905 Bytes
/
RedixConvert.java
File metadata and controls
43 lines (35 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package jmeterClass;
//进制转换类
public class RedixConvert {
public int sourceRedix;
public int targetRedix;
public Object objToConvert;
public String strToConvert;
public RedixConvert( Object objToConvert,int sourceRedix, int targetRedix) {
this.objToConvert = objToConvert;
this.sourceRedix = sourceRedix;
this.targetRedix = targetRedix;
this.strToConvert = objToConvert.toString();
}
public String convert(){
//先全部转换为10进制
int temp10 = Integer.valueOf(strToConvert, sourceRedix);
//System.out.println("temp10="+temp10);
String result = "";
switch(targetRedix){
case 2:
result = Integer.toBinaryString(temp10);
break;
case 8:
result = Integer.toOctalString(temp10);
break;
case 10:
result = temp10+"";
break;
case 16:
result = Integer.toHexString(temp10);
break;
}
return result;
}
}