forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUInteger.java
More file actions
61 lines (47 loc) · 1.29 KB
/
Copy pathUInteger.java
File metadata and controls
61 lines (47 loc) · 1.29 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package javaforce;
/** Unsigned Integer
*
* @author pquiring
*/
public class UInteger {
public static final int MIN_VALUE = 0;
public static final int MAX_VALUE = 0xffffffff;
public static final int MASK = 0xffffffff;
private int value;
public UInteger(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public static int valueOf(String s, int radix) throws NumberFormatException {
return Integer.parseUnsignedInt(s, radix);
}
public static int valueOf(String s) {
return valueOf(s, 10);
}
public static String toString(int value, int radix) {
return Integer.toUnsignedString(value, radix);
}
public static String toString(int value) {
return toString(value, 10);
}
public static int compare(int v1, int v2) {
return Integer.compareUnsigned(v1, v2);
}
public static int divide(int v1, int v2) {
return Integer.divideUnsigned(v1, v2);
}
public static int remainder(int v1, int v2) {
return Integer.remainderUnsigned(v1, v2);
}
public static void main(String[] args) {
int val = 0x00;
for(int a=0;a<16;a++) {
String str = toString(val, 16);
int v2 = valueOf(str, 16);
JFLog.log("int:" + (val & MASK) + " > " + str + " > " + (v2 & MASK));
val += 0x11111111;
}
}
}