Class Signed16

java.lang.Object
com.io7m.jintegers.Signed16

public final class Signed16 extends Object
16-bit signed integer packing/unpacking functions.
  • Method Details

    • packToBytesBigEndianAllocate

      public static byte[] packToBytesBigEndianAllocate(int i)

      Pack i into a byte buffer b using a big-endian encoding such that the most significant byte is in b[0].

      Parameters:
      i - The value to be packed.
      Returns:
      A byte buffer containing the packed integer data.
    • packToBytesBigEndian

      public static byte[] packToBytesBigEndian(int i, byte[] r)

      Pack i into a byte buffer r using a big-endian encoding such that the most significant byte is in r[0].

      Parameters:
      r - The buffer.
      i - The value to be packed.
      Returns:
      r
    • packToBufferBigEndian

      public static ByteBuffer packToBufferBigEndian(int i, ByteBuffer r, int index)

      Pack i into a byte buffer r using a big-endian encoding such that the most significant byte is in r[index].

      Parameters:
      r - The buffer.
      i - The value to be packed.
      index - The starting index.
      Returns:
      r
    • packToBytesLittleEndianAllocate

      public static byte[] packToBytesLittleEndianAllocate(int i)

      Pack i into a byte buffer b using a little-endian encoding such that the least significant byte is in b[0].

      Parameters:
      i - The value to be packed.
      Returns:
      A byte buffer containing the packed integer data.
    • packToBytesLittleEndian

      public static byte[] packToBytesLittleEndian(int i, byte[] r)

      Pack i into a byte buffer r using a little-endian encoding such that the least significant byte is in r[0].

      Parameters:
      r - The buffer.
      i - The value to be packed.
      Returns:
      r
    • packToBufferLittleEndian

      public static ByteBuffer packToBufferLittleEndian(int i, ByteBuffer r, int index)

      Pack i into a byte buffer r using a little-endian encoding such that the least significant byte is in r[index].

      Parameters:
      r - The buffer.
      i - The value to be packed.
      index - The starting index.
      Returns:
      r
    • packToBuffer

      public static ByteBuffer packToBuffer(int i, ByteBuffer r, int index)

      Pack i into a byte buffer r using the encoding returned by ByteBuffer.order(), starting at index.

      Parameters:
      r - The buffer.
      i - The value to be packed.
      index - The starting index.
      Returns:
      r
    • unpackFromBytesBigEndian

      public static int unpackFromBytesBigEndian(byte[] buffer)

      Unpack an integer from buffer assuming a big-endian encoding such that the most significant byte is in b[0].

      The function throws IllegalArgumentException if buffer.length is too small to contain a packed integer value of this size.

      Parameters:
      buffer - The buffer from which to unpack data.
      Returns:
      A 16 bit integer value.
    • unpackFromBufferBigEndian

      public static int unpackFromBufferBigEndian(ByteBuffer buffer, int index)

      Unpack an integer from buffer assuming a big-endian encoding such that the most significant byte is in b[index].

      Parameters:
      index - The starting index in the buffer.
      buffer - The buffer from which to unpack data.
      Returns:
      A 16 bit integer value.
    • unpackFromBuffer

      public static int unpackFromBuffer(ByteBuffer buffer, int index)

      Unpack an integer from buffer using the encoding returned by ByteBuffer.order(), starting at index.

      Parameters:
      index - The starting index
      buffer - The buffer from which to unpack data.
      Returns:
      A 16 bit integer value.
    • unpackFromBytesLittleEndian

      public static int unpackFromBytesLittleEndian(byte[] buffer)

      Unpack an integer from buffer assuming a little-endian encoding such that the least significant byte is in b[0].

      The function throws IllegalArgumentException if buffer.length is too small to contain a packed integer value of this size.

      Parameters:
      buffer - The buffer from which to unpack data.
      Returns:
      A 16 bit integer value.
    • unpackFromBufferLittleEndian

      public static int unpackFromBufferLittleEndian(ByteBuffer buffer, int index)

      Unpack an integer from buffer assuming a little-endian encoding such that the least significant byte is in b[index] .

      Parameters:
      index - The starting index
      buffer - The buffer from which to unpack data.
      Returns:
      A 16 bit integer value.