summaryrefslogtreecommitdiff
path: root/dslog/Util.java
diff options
context:
space:
mode:
Diffstat (limited to 'dslog/Util.java')
-rw-r--r--dslog/Util.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/dslog/Util.java b/dslog/Util.java
new file mode 100644
index 0000000..b430af9
--- /dev/null
+++ b/dslog/Util.java
@@ -0,0 +1,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);
+ }
+}