Package org.gvsig.dwg.lib.util
Class HexUtil
java.lang.Object
org.gvsig.dwg.lib.util.HexUtil
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 Summary
Modifier and TypeMethodDescriptionstatic final byte[]bitsToBytes(BitSet ba, int size) Pack the bits in ba into a byte[].static final StringbitsToHexString(BitSet ba, int size) Pack the bits in ba into a byte[] then convert that to a hex string and return it.static voidbytesToBits(byte[] b, BitSet ba, int maxSize) Read bits from a byte array into a bitsetstatic final StringbytesToHex(byte[] bs) static final StringbytesToHex(byte[] bs, int off, int length) Converts a byte array into a string of upper case hex chars.static final voidbytesToHexAppend(byte[] bs, int off, int length, StringBuffer sb) static intcountBytesForBits(int size) static voidRead a hex string of bits and write it into a bitsetstatic final byte[]hexToBytes(String s) static final voidhexToBytes(String s, byte[] out, int off) Converts a String of hex characters into an array of bytes.static final byte[]hexToBytes(String s, int off)
-
Method Details
-
bytesToHex
Converts a byte array into a string of upper case hex chars.- Parameters:
bs- A byte arrayoff- The index of the first byte to readlength- The number of bytes to read.- Returns:
- the string of hex chars.
-
bytesToHexAppend
-
bytesToHex
-
hexToBytes
-
hexToBytes
-
hexToBytes
public static final void hexToBytes(String s, byte[] out, int off) throws NumberFormatException, IndexOutOfBoundsException Converts a String of hex characters into an array of bytes.- Parameters:
s- A string of hex characters (upper case or lower) of even length.out- A byte array of length at least s.length()/2 + offoff- The first byte to write of the array- Throws:
NumberFormatExceptionIndexOutOfBoundsException
-
bitsToBytes
Pack the bits in ba into a byte[]. -
bitsToHexString
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
Read bits from a byte array into a bitset- Parameters:
b- the byte[] to read fromba- the bitset to write to
-
hexToBits
Read a hex string of bits and write it into a bitset- Parameters:
s- hex string of the stored bitsba- the bitset to store the bits inlength- the maximum number of bits to store
-