com.jaccal.util
Class NumUtil

java.lang.Object
  extended bycom.jaccal.util.NumUtil

public class NumUtil
extends Object

A utility class mainly used for display of bytes to string and vice versa

Author:
Chang Sau Sheong

Field Summary
private static char[] hexChar
           
private static String hexits
           
 
Constructor Summary
NumUtil()
           
 
Method Summary
static int getUnsignedValue(byte b)
          Get the unsigned value of a byte.
static String hex2String(byte[] b)
          Convert a byte array into its hexadecimal string representation.
static int HexToDec(int hex)
          Convert from hexadecimal base to decimal base.
static byte[] int2ByteArray(int inCode)
          Convert an integer into a byte array.
static String int2HexString(int in)
          Convert an integer into its hexadecimal String representation.
static String toHexString(byte[] b)
          Convert a byte array into its hexadecimal string representation.
static byte[] toStringHex(String s)
          Convert a String (hexadecimal representation of a bytes) into a byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hexChar

private static char[] hexChar

hexits

private static String hexits
Constructor Detail

NumUtil

public NumUtil()
Method Detail

toHexString

public static String toHexString(byte[] b)
Convert a byte array into its hexadecimal string representation. A space character is added in between each byte value. Example: byte [] b = {0x00,0x11,0x22,0xAA}, the returned String will be "00 11 22 AA"

Parameters:
b - the byte array to convert into a String
Returns:
The String representation of the byte array

hex2String

public static String hex2String(byte[] b)
Convert a byte array into its hexadecimal string representation. No space character is added in between each byte value. Example: byte [] b = {0x00,0x11,0x22,0xAA}, the returned String will be "001122AA"

Parameters:
b -
Returns:
The hexadecimal representation of the byte array

HexToDec

public static int HexToDec(int hex)
Convert from hexadecimal base to decimal base.

Parameters:
hex -
Returns:
The integer representation of the hexadecimal number

toStringHex

public static byte[] toStringHex(String s)
Convert a String (hexadecimal representation of a bytes) into a byte array. Example: "112233AA", the returned byte[] will be: {0x11,0x22,0x33,0xAA}

Parameters:
s - the String to convert
Returns:
The String representation of the bytes

int2ByteArray

public static byte[] int2ByteArray(int inCode)
Convert an integer into a byte array. The returned byte array is 4 byte length.

Parameters:
inCode -
Returns:
A byte array

int2HexString

public static String int2HexString(int in)
Convert an integer into its hexadecimal String representation. Example: in = 0xAA11EECC, the returned String will be "AA11EECC"

Parameters:
in -
Returns:
The String version of the integer

getUnsignedValue

public static int getUnsignedValue(byte b)
Get the unsigned value of a byte.

Parameters:
b -
Returns:
An unsigned integer of the value


Copyright © 2005 Chang Sau Sheong, Thomas Tarpin-Lyonnet. All Rights Reserved.