static public char[] convertByteToChar(byte[] byteArray) { int size = byteArray.length; char[] cbuff = new char[size]; for (int i = 0; i < size; i++) cbuff[i] = (char) DataType.unsignedByteToShort(byteArray[i]); // NOTE: not Unicode ! return cbuff; }
static public char[] convertByteToChar(byte[] byteArray) { int size = byteArray.length; char[] cbuff = new char[size]; for (int i = 0; i < size; i++) cbuff[i] = (char) DataType.unsignedByteToShort(byteArray[i]); // NOTE: not Unicode ! return cbuff; }
static boolean isZlibHed(byte[] buf) { short b0 = DataType.unsignedByteToShort(buf[0]); short b1 = DataType.unsignedByteToShort(buf[1]); if ((b0 & 0xf) == Z_DEFLATED) { if ((b0 >> 4) + 8 <= DEF_WBITS) { if ((((b0 << 8) + b1) % 31) == 0) { return true; } } } return false; }
static public char[] convertByteToChar(byte[] byteArray) { int size = byteArray.length; char[] cbuff = new char[size]; for (int i = 0; i < size; i++) cbuff[i] = (char) DataType.unsignedByteToShort(byteArray[i]); // NOTE: not Unicode ! return cbuff; }
public float getFloat(int index) { byte val = storage[index]; return (float) (unsigned ? DataType.unsignedByteToShort(val) : val); }
public int getInt(int index) { byte val = storage[index]; return (int) (unsigned ? DataType.unsignedByteToShort(val) : val); }
public static void main(String[] args) { for (int i=0; i<260; i++) { byte b = (byte) i; System.out.printf("%4d = %4d%n", b, unsignedByteToShort(b)); } }
public static void main(String[] args) { for (int i=0; i<260; i++) { byte b = (byte) i; System.out.printf("%4d = %4d%n", b, unsignedByteToShort(b)); } }
public static int countBits(byte[] bitmap) { int bits = 0; for (byte b : bitmap) { short s = DataType.unsignedByteToShort(b); bits += Long.bitCount(s); } return bits; }
private double readScaledInt(ByteBuffer buf) { // Get the first two bytes short s1 = buf.getShort(); // And the last one as unsigned short s2 = DataType.unsignedByteToShort(buf.get()); // Get the sign bit, converting from 0 or 2 to +/- 1. int posneg = 1 - ((s1 & 0x8000) >> 14); // Combine the first two bytes (without sign bit) with the last byte. // Multiply by proper factor for +/- int nn = (((s1 & 0x7FFF) << 8) | s2) * posneg; return (double) nn / 10000.0; }
/** * Convert unsigned bytes into an integer. * * @param raf read one byte from here * @return integer value * @throws IOException on read error */ public static int uint(RandomAccessFile raf) throws IOException { int a = raf.read(); return (int) DataType.unsignedByteToShort((byte) a); }
public double getDouble(Index i) { byte val = storage[i.currentElement()]; return (double) (unsigned ? DataType.unsignedByteToShort(val) : val); }
public int getInt(Index i) { byte val = storage[i.currentElement()]; return (int) (unsigned ? DataType.unsignedByteToShort(val) : val); }
public double getDouble(Index i) { byte val = storage[i.currentElement()]; return (double) (unsigned ? DataType.unsignedByteToShort(val) : val); }
public double convertScaleOffsetMissing(byte valb) { if (!hasScaleOffset) return useNaNs && isMissing((double) valb) ? Double.NaN : (double) valb; double convertedValue; if (isUnsigned) convertedValue = scale * DataType.unsignedByteToShort(valb) + offset; else convertedValue = scale * valb + offset; return useNaNs && isMissing(convertedValue) ? Double.NaN : convertedValue; }
public double convertScaleOffsetMissing(byte valb) { if (!hasScaleOffset) return useNaNs && isMissing((double) valb) ? Double.NaN : (double) valb; double convertedValue; if (isUnsigned) convertedValue = scale * DataType.unsignedByteToShort(valb) + offset; else convertedValue = scale * valb + offset; return useNaNs && isMissing(convertedValue) ? Double.NaN : convertedValue; }
public static void main(String[] args) { System.out.printf("byte == convertSignedByte == convertSignedByte2 == hex%n"); for (int i=125; i<256;i++) { byte b = (byte) i; System.out.printf("%d == %d == %d == %s%n", b, convertSignedByte(b), convertSignedByte2(b), Long.toHexString((long) i)); assert convertSignedByte(b) == convertSignedByte2(b) : convertSignedByte(b) +"!=" +convertSignedByte2(b); } int val = (int) DataType.unsignedByteToShort((byte) -200); int val2 = DataType.unsignedShortToInt((short) -200); System.out.printf("%d != %d%n", val, val2); }
private void convertScaleOffsetUnsignedByte(IndexIterator iterIn, IndexIterator iterOut) { boolean checkMissing = useNaNs && hasMissing(); while (iterIn.hasNext()) { byte valb = iterIn.getByteNext(); double val = scale * DataType.unsignedByteToShort(valb) + offset; iterOut.setDoubleNext(checkMissing && isMissing_(val) ? Double.NaN : val); } }
private void convertScaleOffsetUnsignedByte(IndexIterator iterIn, IndexIterator iterOut) { boolean checkMissing = useNaNs && hasMissing(); while (iterIn.hasNext()) { byte valb = iterIn.getByteNext(); double val = scale * DataType.unsignedByteToShort(valb) + offset; iterOut.setDoubleNext(checkMissing && isMissing_(val) ? Double.NaN : val); } }
public long convertScalarLong(int recnum, StructureMembers.Member m) { if (m.getDataType() == DataType.LONG || m.getDataType() == DataType.ULONG) return getScalarLong(recnum, m); if (m.getDataType() == DataType.INT) return (long) getScalarInt(recnum, m); if (m.getDataType() == DataType.UINT) return DataType.unsignedIntToLong( getScalarInt(recnum, m)); if (m.getDataType() == DataType.SHORT) return (long) getScalarShort(recnum, m); if (m.getDataType() == DataType.USHORT) return (long) DataType.unsignedShortToInt(getScalarShort(recnum, m)); if (m.getDataType() == DataType.BYTE) return (long) getScalarByte(recnum, m); if (m.getDataType() == DataType.UBYTE) return (long) DataType.unsignedByteToShort(getScalarByte(recnum, m)); Object o = getScalarObject(recnum, m); if (o instanceof Number) return ((Number) o).longValue(); throw new ForbiddenConversionException("Type is " + m.getDataType() + ", not convertible to int"); }