/** * Convert signed bytes to a 16-bit short float value. */ private static float bytesToFloat(final byte b0, final byte b1) { int mantissa = unsignedToSigned(unsignedByteToInt(b0) + ((unsignedByteToInt(b1) & 0x0F) << 8), 12); int exponent = unsignedToSigned(unsignedByteToInt(b1) >> 4, 4); return (float) (mantissa * Math.pow(10, exponent)); }
/** * Convert signed bytes to a 32-bit short float value. */ private static float bytesToFloat(final byte b0, final byte b1, final byte b2, final byte b3) { int mantissa = unsignedToSigned(unsignedByteToInt(b0) + (unsignedByteToInt(b1) << 8) + (unsignedByteToInt(b2) << 16), 24); return (float) (mantissa * Math.pow(10, b3)); }
/** * Returns a long value from the byte array. * <p>Only {@link #FORMAT_UINT32} and {@link #FORMAT_SINT32} are supported. * <p>The formatType parameter determines how the value * is to be interpreted. For example, setting formatType to * {@link #FORMAT_UINT32} specifies that the first four bytes of the * value at the given offset are interpreted to generate the * return value. * * @param formatType The format type used to interpret the value. * @param offset Offset at which the integer value can be found. * @return Cached value or null of offset exceeds value size. */ @Nullable public Long getLongValue(@LongFormat final int formatType, @IntRange(from = 0) final int offset) { if ((offset + getTypeLen(formatType)) > size()) return null; switch (formatType) { case FORMAT_SINT32: return unsignedToSigned(unsignedBytesToLong(mValue[offset], mValue[offset + 1], mValue[offset + 2], mValue[offset + 3]), 32); case FORMAT_UINT32: return unsignedBytesToLong(mValue[offset], mValue[offset + 1], mValue[offset + 2], mValue[offset + 3]); } return null; }
return unsignedToSigned(unsignedByteToInt(mValue[offset]), 8); return unsignedToSigned(unsignedBytesToInt(mValue[offset], mValue[offset + 1]), 16); return unsignedToSigned(unsignedBytesToInt(mValue[offset], mValue[offset + 1], mValue[offset + 2], (byte) 0), 24); return unsignedToSigned(unsignedBytesToInt(mValue[offset], mValue[offset + 1], mValue[offset + 2], mValue[offset + 3]), 32);