-
Notifications
You must be signed in to change notification settings - Fork 0
/
ByteReader.java
53 lines (43 loc) · 1.41 KB
/
ByteReader.java
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
/*
* Created on Dec 11, 2006
* Dec 11, 2006 6:34:11 PM
*/
public final class ByteReader
{
public static final int Read8(byte[] data, int offset, int numsex)
{
return data[offset] & 0xff;
}
public static final int Read8(byte[] data, int offset)
{
return data[offset] & 0xff;
}
public static final int Read16(byte[] data, int offset, int numsex)
{
int x1 = data[offset++] & 0x00ff;
int x2 = data[offset++] & 0x00ff;
if (numsex == 0)
return x1 | (x2 << 8);
return (x1 << 8) | x2;
}
public static final int Read24(byte[] data, int offset, int numsex)
{
int x1 = data[offset++] & 0x00ff;
int x2 = data[offset++] & 0x00ff;
int x3 = data[offset++] & 0x00ff;
if (numsex == 0)
return x1 | (x2 << 8) | (x3 << 16);
return (x1 << 16) | (x2 << 8) | x3;
}
public static final int Read32(byte[] data, int offset, int numsex)
{
int x1 = data[offset++] & 0x00ff;
int x2 = data[offset++] & 0x00ff;
int x3 = data[offset++] & 0x00ff;
int x4 = data[offset++] & 0x00ff;
if (numsex == 0)
return x1 | (x2 << 8) | (x3 << 16) | (x4 << 24);
return (x1 << 24) | (x2 << 16) | (x3 << 8) | x4;
}
private ByteReader() {}
}