2 * Sixth - System for data storage, computation, exploration and interaction.
3 * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 3 of the GNU Lesser General Public License
7 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.sixth.data.model;
12 public class ArrayStorage {
14 // load 16bit integer from byte array
15 public static int load16bit(final byte[] array, final int addr) {
16 // return (int)array[addr] + (int)array[addr+1]*256;
17 return ((array[addr + 1] & 0xFF) << 8) | (array[addr] & 0xFF);
20 // load 16bit integer from byte array
21 public static int load32bit(final byte[] array, final int addr) {
22 return ((array[addr + 3] & 0xFF) << 24)
23 | ((array[addr + 2] & 0xFF) << 16)
24 | ((array[addr + 1] & 0xFF) << 8) | (array[addr] & 0xFF);
27 // store 16bit integer into byte array
28 public static void store16bit(final byte[] array, final int addr,
30 final int byteHigh = value / 256;
31 final int byteLow = value - (byteHigh * 256);
32 array[addr] = (byte) byteLow;
33 array[addr + 1] = (byte) byteHigh;