Class HexUtil


  • public class HexUtil
    extends Object
    Number in hexadecimal format are used throughout Freenet.

    Unless otherwise stated, the conventions follow the rules outlined in the Java Language Specification.

    Author:
    syoung
    • Method Detail

      • bytesToHex

        public static final String bytesToHex​(byte[] bs,
                                              int off,
                                              int length)
        Converts a byte array into a string of upper case hex chars.
        Parameters:
        bs - A byte array
        off - The index of the first byte to read
        length - The number of bytes to read.
        Returns:
        the string of hex chars.
      • bytesToHexAppend

        public static final void bytesToHexAppend​(byte[] bs,
                                                  int off,
                                                  int length,
                                                  StringBuffer sb)
      • bytesToHex

        public static final String bytesToHex​(byte[] bs)
      • hexToBytes

        public static final byte[] hexToBytes​(String s)
      • hexToBytes

        public static final byte[] hexToBytes​(String s,
                                              int off)
      • bitsToBytes

        public static final byte[] bitsToBytes​(BitSet ba,
                                               int size)
        Pack the bits in ba into a byte[].
      • bitsToHexString

        public static final String bitsToHexString​(BitSet ba,
                                                   int size)
        Pack the bits in ba into a byte[] then convert that to a hex string and return it.
      • countBytesForBits

        public static int countBytesForBits​(int size)
        Returns:
        the number of bytes required to represent the bitset
      • bytesToBits

        public static void bytesToBits​(byte[] b,
                                       BitSet ba,
                                       int maxSize)
        Read bits from a byte array into a bitset
        Parameters:
        b - the byte[] to read from
        ba - the bitset to write to
      • hexToBits

        public static void hexToBits​(String s,
                                     BitSet ba,
                                     int length)
        Read a hex string of bits and write it into a bitset
        Parameters:
        s - hex string of the stored bits
        ba - the bitset to store the bits in
        length - the maximum number of bits to store