summaryrefslogtreecommitdiff
path: root/dslog/Util.java
blob: b430af9ff3f5631f8c2aac438cb3f9fa78b1b9cb (plain)
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
package dslog;

import java.io.InputStream;

class Util {
	public static int[] concat(int[]... lists) {
		int len = 0;
		for (int[] list : lists) {
			len += list.length;
		}
		int[] ret = new int[len];
		int n = 0;
		for (int[] list : lists) {
			System.arraycopy(list, 0, ret, n, list.length);
			n += list.length;
		}
		return ret;
	}

	public static int[] reverse(int[] list) {
		int mid = list.length / 2;
		int tmp;
		for (int i = 0; i < mid; i++) {
			tmp = list[i];
			list[i] = list[list.length - i - 1];
			list[list.length - i - 1] = tmp;
		}
		return list;
	}
		
	public static double unpack(short val, int whole, int frac) {
		switch (whole + frac) {
		case 8:
		case 10:
			break;
		default:
			throw new IllegalArgumentException(whole+"+"+frac+" != 8|10");
		}
		return val / Math.pow(2, frac);
	}

	public static double unpack(int val, int whole, int frac) {
		switch (whole + frac) {
		case 16:
			break;
		default:
			throw new IllegalArgumentException(whole+"+"+frac+" != 16");
		}
		return val / Math.pow(2, frac);
	}
}