Source code: plugins/IcqEngine/protocol/ByteDecoder.java
1 /*
2 * IntDecoder.java
3 *
4 * Created on October 31, 2002, 6:19 PM
5 */
6
7 package plugins.IcqEngine.protocol;
8
9 /**
10 *
11 * @author Tobias Riemer
12 */
13 public class ByteDecoder {
14
15 /** Creates a new instance of IntDecoder */
16 public ByteDecoder() {
17 }
18
19 static public int decodeInt(byte[] b,int from,int to) {
20 int i = 0;
21 for (int j=to-1;j>=from;j--) {
22 i=i<<8;
23 if ((int)b[j] >= 0)
24 i += (int) b[j];
25 else
26 i += ((int)(256+b[j]));
27 }
28 return i;
29 }
30
31 static public int decodeHex(byte[] b,int from,int to) {
32 int i = 0;
33 for (int j=from;j<to;j++) {
34 i=i<<8;
35 if ((int)b[j] >= 0)
36 i += (int) b[j];
37 else
38 i += ((int)(256+b[j]));
39 }
40 return i;
41 }
42 }