forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUShort.java
More file actions
57 lines (45 loc) · 1.26 KB
/
Copy pathUShort.java
File metadata and controls
57 lines (45 loc) · 1.26 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
package javaforce;
/** Unsigned Short
*
* @author pquiring
*/
public class UShort {
public static final int MIN_VALUE = 0;
public static final int MAX_VALUE = 0xffff;
public static final int MASK = 0xffff;
private short value;
public UShort(short value) {
this.value = value;
}
public short getValue() {
return value;
}
public static short valueOf(String s, int radix) throws NumberFormatException {
int value = Integer.parseUnsignedInt(s, radix);
if (value < MIN_VALUE || value > MAX_VALUE) {
throw new NumberFormatException("UShort:value out of range");
}
return (short)value;
}
public static short valueOf(String s) {
return valueOf(s, 10);
}
public static String toString(short value, int radix) {
return Integer.toString(value & 0xffff, radix);
}
public static String toString(short value) {
return toString(value, 10);
}
public static int compare(short v1, short v2) {
return Short.compareUnsigned(v1, v2);
}
public static void main(String[] args) {
short val = 0x00;
for(int a=0;a<16;a++) {
String str = toString(val, 16);
short v2 = valueOf(str, 16);
JFLog.log("short:" + (val & MASK) + " > " + str + " > " + (v2 & MASK));
val += 0x1111;
}
}
}