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