Elexis API documentation
Version 2.1.6 as of December 11 2011

ch.rgw.tools
Class BinConverter

java.lang.Object
  extended by ch.rgw.tools.BinConverter

public class BinConverter
extends java.lang.Object

Some helper routines for data conversion, all data is treated in network byte order.


Constructor Summary
BinConverter()
           
 
Method Summary
static int byteArrayToInt(byte[] buf, int nOfs)
          Gets bytes from an array into an integer.
static long byteArrayToLong(byte[] buf, int nOfs)
          Gets bytes from an array into a long.
static java.lang.String byteArrayToStr(byte[] data, int nOfs, int nLen)
          Converts a byte array into a Unicode string.
static java.lang.String bytesToHexStr(byte[] data)
          Converts a byte array to a hex string.
static java.lang.String bytesToHexStr(byte[] data, int nOfs, int nLen)
          Converts a byte array to a hex string.
static int hexStrToBytes(java.lang.String sHex, byte[] data, int nSrcOfs, int nDstOfs, int nLen)
          Converts a hex string back into a byte array (invalid codes will be skipped).
static long intArrayToLong(int[] buf, int nOfs)
          Converts values from an integer array to a long.
static void intToByteArray(int nValue, byte[] buf, int nOfs)
          Converts an integer to bytes, which are put into an array.
static int longHi32(long lVal)
          Gets the higher 32 bits of a long.
static int longLo32(long lVal)
          Gets the lower 32 bits of a long.
static void longToByteArray(long lValue, byte[] buf, int nOfs)
          Converts a long to bytes, which are put into an array.
static void longToIntArray(long lValue, int[] buf, int nOfs)
          Converts a long to integers which are put into an array.
static long makeLong(int nLo, int nHi)
          Makes a long from two integers (treated unsigned).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinConverter

public BinConverter()
Method Detail

byteArrayToInt

public static final int byteArrayToInt(byte[] buf,
                                       int nOfs)
Gets bytes from an array into an integer.

Parameters:
buf - where to get the bytes
nOfs - index from where to read the data
Returns:
the 32bit integer

intToByteArray

public static final void intToByteArray(int nValue,
                                        byte[] buf,
                                        int nOfs)
Converts an integer to bytes, which are put into an array.

Parameters:
nValue - the 32bit integer to convert
buf - the target buf
nOfs - where to place the bytes in the buf

byteArrayToLong

public static final long byteArrayToLong(byte[] buf,
                                         int nOfs)
Gets bytes from an array into a long.

Parameters:
buf - where to get the bytes
nOfs - index from where to read the data
Returns:
the 64bit integer

longToByteArray

public static final void longToByteArray(long lValue,
                                         byte[] buf,
                                         int nOfs)
Converts a long to bytes, which are put into an array.

Parameters:
lValue - the 64bit integer to convert
buf - the target buf
nOfs - where to place the bytes in the buf

intArrayToLong

public static final long intArrayToLong(int[] buf,
                                        int nOfs)
Converts values from an integer array to a long.

Parameters:
buf - where to get the bytes
nOfs - index from where to read the data
Returns:
the 64bit integer

longToIntArray

public static final void longToIntArray(long lValue,
                                        int[] buf,
                                        int nOfs)
Converts a long to integers which are put into an array.

Parameters:
lValue - the 64bit integer to convert
buf - the target buf
nOfs - where to place the bytes in the buf

makeLong

public static final long makeLong(int nLo,
                                  int nHi)
Makes a long from two integers (treated unsigned).

Parameters:
nLo - lower 32bits
nHi - higher 32bits
Returns:
the built long

longLo32

public static final int longLo32(long lVal)
Gets the lower 32 bits of a long.

Parameters:
lVal - the long integer
Returns:
lower 32 bits

longHi32

public static final int longHi32(long lVal)
Gets the higher 32 bits of a long.

Parameters:
lVal - the long integer
Returns:
higher 32 bits

bytesToHexStr

public static final java.lang.String bytesToHexStr(byte[] data)
Converts a byte array to a hex string.

Parameters:
data - the byte array
Returns:
the hex string

bytesToHexStr

public static final java.lang.String bytesToHexStr(byte[] data,
                                                   int nOfs,
                                                   int nLen)
Converts a byte array to a hex string.

Parameters:
data - the byte array
nOfs - start index where to get the bytes
nLen - number of bytes to convert
Returns:
the hex string

hexStrToBytes

public static final int hexStrToBytes(java.lang.String sHex,
                                      byte[] data,
                                      int nSrcOfs,
                                      int nDstOfs,
                                      int nLen)
Converts a hex string back into a byte array (invalid codes will be skipped).

Parameters:
sHex - hex string
data - the target array
nSrcOfs - from which character in the string the conversion should begin, remember that (nSrcPos modulo 2) should equals 0 normally
nDstOfs - to store the bytes from which position in the array
nLen - number of bytes to extract
Returns:
number of extracted bytes

byteArrayToStr

public static final java.lang.String byteArrayToStr(byte[] data,
                                                    int nOfs,
                                                    int nLen)
Converts a byte array into a Unicode string.

Parameters:
data - the byte array
nOfs - where to begin the conversion
nLen - number of bytes to handle
Returns:
the string

Elexis API documentation
Version 2.1.6 as of December 11 2011

Copyright 2005-2011 by Gerry Weirich, Elexis