com.cafesoft.core.util
Class HexUtils

java.lang.Object
  |
  +--com.cafesoft.core.util.HexUtils

public final class HexUtils
extends Object

Library of utility methods useful in dealing with converting byte arrays to and from strings of hexadecimal digits.


Field Summary
static int[] DEC
           
 
Constructor Summary
HexUtils()
           
 
Method Summary
static String convert(byte[] bytes)
          Convert a byte array into a printable format containing a String of hexadecimal digit characters (two per byte).
static byte[] convert(String digits)
          Convert a String of hexadecimal digits into the corresponding byte array by encoding each two hexadecimal digits as a byte.
static int convert2Int(byte[] hex)
          Convert 4 hex digits to an int, and return the number of converted bytes.
static boolean isHexDigit(char ch)
          Determine if character is a valid hex digit or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEC

public static final int[] DEC
Constructor Detail

HexUtils

public HexUtils()
Method Detail

convert

public static byte[] convert(String digits)
Convert a String of hexadecimal digits into the corresponding byte array by encoding each two hexadecimal digits as a byte.

Parameters:
digits - Hexadecimal digits representation
Throws:
IllegalArgumentException - if an invalid hexadecimal digit is found, or the input string contains an odd number of hexadecimal digits

convert

public static String convert(byte[] bytes)
Convert a byte array into a printable format containing a String of hexadecimal digit characters (two per byte).

Parameters:
bytes - Byte array representation

convert2Int

public static int convert2Int(byte[] hex)
Convert 4 hex digits to an int, and return the number of converted bytes.

Parameters:
hex - Byte array containing exactly four hexadecimal digits
Throws:
IllegalArgumentException - if an invalid hexadecimal digit is included

isHexDigit

public static final boolean isHexDigit(char ch)
Determine if character is a valid hex digit or not.

A valid hex digit satisfies the following requirements:

  • the character is a digit (0..9)
  • the character is a lowercase a,b,c,d,e,f
  • the character is a uppercase A,B,C,D,E,F

    Parameters:
    ch - the character to test
    Returns:
    return true if the character is a hex digit, false otherwise


  • Generated on 8:41:50 AM June 06, 2005, © 1996-2005 Cafésoft LLC. All rights reserved.