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