-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathIntField.java
More file actions
47 lines (38 loc) · 1.15 KB
/
IntField.java
File metadata and controls
47 lines (38 loc) · 1.15 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
/*
Written 1999 by Douglas Greiman.
This software may be used and distributed according to the terms
of the GNU Public License, incorporated herein by reference.
*/
package duggelz.jape;
class IntField implements Field
{
private int offset;
public IntField(int offset)
{
this.offset = offset;
}
public String get(byte[] data)
{
return Integer.toString(this.getInt(data));
}
public int getInt(byte[] data)
{
int value = ( (((int) data[this.offset]) & 0xFF) |
((((int) data[this.offset + 1]) & 0xFF) << 8) |
((((int) data[this.offset + 2]) & 0xFF) << 16) |
((((int) data[this.offset + 3]) & 0xFF) << 24) );
return value;
}
public void set(byte[] data, String str) throws NumberFormatException
{
int value = Integer.parseInt(str);
this.setInt(data, value);
}
public void setInt(byte[] data, int value)
{
data[this.offset] = (byte) (value & 0xFF);
data[this.offset + 1] = (byte) ((value >>> 8) & 0xFF);
data[this.offset + 2] = (byte) ((value >>> 16) & 0xFF);
data[this.offset + 3] = (byte) ((value >>> 24) & 0xFF);
}
}