Module id.xfunction
Package id.xfunction

Class XByte

Object
XByte

public class XByte extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    copyAsByteLiterals(int... byteLiterals)
    Java does not allow you to specify byte literals in form of 0xff (which is int literal in Java).
    static byte[]
    copyToByteArray(int... ints)
    Resulting byte array size will be ints.length * Integer.BYTES
    static byte[]
    copyToByteArray(long... longs)
    Resulting byte array size will be longs.length * Long.BYTES
    static byte[]
     
    static byte[]
    static byte
    reverseBits(byte b)
    Reverse bits in the byte
    static int
    Reverse bits in the bytes of the int.
    static String
    toHex(byte... a)
    Returns a string representation of the byte array as a hexadecimal string.
    static String
    toHex(int... a)
     
    static String
    toHexPair(byte b)
    Returns a hexadecimal pair string representation of the given byte.
    static String
    toHexPairs(byte... a)
    Works same way as toHex(byte...) except it formats the resulting string as pairs of bytes separated with white spaces
    static String
    toHexPairs(int i)
    Converts int to hexadecimal pairs string.
    static int
    toInt(byte[] arrayOf4Bytes)
    Equivalent to:
    static int
    toInt(int byte1st)
     
    static int
    toInt(int byte1st, int byte2nd)
     
    static int
    toInt(int byte1st, int byte2nd, int byte3rd)
     
    static int
    toInt(int byte1st, int byte2nd, int byte3rd, int byte4st)
     
    static short
    toShort(int byte1st)
     
    static short
    toShort(int byte1st, int byte2nd)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • XByte

      public XByte()
  • Method Details

    • toHex

      public static String toHex(byte... a)
      Returns a string representation of the byte array as a hexadecimal string.

      Each byte of the array is converted to the code base 16. The code is padded with 0 at the front if its length is less than 2. It means that length of the code is always 2 symbols: a - 0a

      Example:

      
       XByte.toHex("hello world".getBytes())
       

      Will return string "68656c6c6f20776f726c64".

    • toHex

      public static String toHex(int... a)
    • fromHex

      public static byte[] fromHex(String hex)
    • toHexPairs

      public static String toHexPairs(byte... a)
      Works same way as toHex(byte...) except it formats the resulting string as pairs of bytes separated with white spaces

      Example:

      
       XByte.toHexPairs("hello world".getBytes())
       

      Will return string "68 65 6c 6c 6f 20 77 6f 72 6c 64".

    • fromHexPairs

      public static byte[] fromHexPairs(String hex)
    • toHexPairs

      public static String toHexPairs(int i)
      Converts int to hexadecimal pairs string.

      Example:

      
       XByte.toHexPairs(123)
       

      Will return string "00 00 00 7b".

    • toHexPair

      public static String toHexPair(byte b)
      Returns a hexadecimal pair string representation of the given byte.

      The code is padded with 0 at the front if its length is less than 2. It means that length of the code is always 2 symbols: a - 0a

    • copyAsByteLiterals

      public static byte[] copyAsByteLiterals(int... byteLiterals)
      Java does not allow you to specify byte literals in form of 0xff (which is int literal in Java). This methods accepts integer literals and cast them to bytes.

      It allows you to create byte[] from int literals like:

      
       var cafe = XByte.copyToByteArray(0xca, 0xfe);
       // instead of
       var cafe = new byte[]{(byte)0xca, (byte)0xfe};
       
    • copyToByteArray

      public static byte[] copyToByteArray(int... ints)
      Resulting byte array size will be ints.length * Integer.BYTES
    • copyToByteArray

      public static byte[] copyToByteArray(long... longs)
      Resulting byte array size will be longs.length * Long.BYTES
    • reverseBits

      public static byte reverseBits(byte b)
      Reverse bits in the byte
    • reverseBitsInBytes

      public static int reverseBitsInBytes(int i)
      Reverse bits in the bytes of the int.

      Example: 0b00000011_00001010 into 0b11000000_01010000

    • toInt

      public static int toInt(int byte1st)
    • toInt

      public static int toInt(int byte1st, int byte2nd)
    • toInt

      public static int toInt(int byte1st, int byte2nd, int byte3rd)
    • toInt

      public static int toInt(int byte1st, int byte2nd, int byte3rd, int byte4st)
    • toInt

      public static int toInt(byte[] arrayOf4Bytes)
      Equivalent to:
      
       return toInt(arrayOf4Bytes[0], arrayOf4Bytes[1], arrayOf4Bytes[2], arrayOf4Bytes[3]);
       
    • toShort

      public static short toShort(int byte1st)
    • toShort

      public static short toShort(int byte1st, int byte2nd)