com.dalsemi.onewire.utils
Class Convert

java.lang.Object
  |
  +--com.dalsemi.onewire.utils.Convert

public class Convert
extends Object

Utilities for conversion between miscellaneous datatypes.

Version:
1.00, 28 December 2001
Author:
SH

Method Summary
static byte[] toByteArray(int intVal)
          This method constructs a LSByte byte array with 4 bytes from an int.
static void toByteArray(int intVal, byte[] byteArray)
          This method constructs a LSByte byte array with 4 bytes from an int.
static void toByteArray(int intVal, byte[] byteArray, int offset, int len)
          This method constructs a LSByte byte array with specified length from an int.
static byte[] toByteArray(long longVal)
          This method constructs a LSByte byte array with 8 bytes from a long.
static void toByteArray(long longVal, byte[] byteArray)
          This method constructs a LSByte byte array with 8 bytes from a long.
static void toByteArray(long longVal, byte[] byteArray, int offset, int len)
          This method constructs a LSByte byte array with specified length from a long.
static byte[] toByteArray(String strData)
          Converts a hex-encoded string into an array of bytes.
static int toByteArray(String strData, byte[] bData)
          Converts a hex-encoded string into an array of bytes.
static int toByteArray(String strData, byte[] bData, int offset, int length)
          Converts a hex-encoded string into an array of bytes.
static double toCelsius(double fahrenheitTemperature)
          Converts a temperature reading from Fahrenheit to Celsius.
static double toFahrenheit(double celsiusTemperature)
          Converts a temperature reading from Celsius to Fahrenheit.
static String toHexString(byte bValue)
          Converts a single byte into a hex-encoded string.
static String toHexString(byte[] data)
          Converts a byte array into a hex-encoded String, using the provided delimeter.
static String toHexString(byte[] data, int offset, int length)
          Converts a byte array into a hex-encoded String, using the provided delimeter.
static String toHexString(byte[] data, int offset, int length, String delimeter)
          Converts a byte array into a hex-encoded String, using the provided delimeter.
static String toHexString(byte[] data, String delimeter)
          Converts a byte array into a hex-encoded String, using the provided delimeter.
static String toHexString(char bValue)
          Converts a single character into a hex-encoded string.
static String toHexString(char[] data)
          Converts a char array into a hex-encoded String, using the provided delimeter.
static String toHexString(char[] data, int offset, int length)
          Converts a byte array into a hex-encoded String, using the provided delimeter.
static String toHexString(char[] data, int offset, int length, String delimeter)
          Converts a char array into a hex-encoded String, using the provided delimeter.
static String toHexString(char[] data, String delimeter)
          Converts a char array into a hex-encoded String, using the provided delimeter.
static String toHexString(int iValue)
          Converts an integer into a hex-encoded string (LSByte).
static String toHexString(long lValue)
          Converts a long into a hex-encoded string (LSByte).
static int toInt(byte[] byteArray)
          This method constructs an int from a LSByte byte array of specified length.
static int toInt(byte[] byteArray, int offset, int len)
          This method constructs an int from a LSByte byte array of specified length.
static int toInt(String strData)
          Converts a hex-encoded string (LSByte) into an int.
static long toLong(byte[] byteArray)
          This method constructs a long from a LSByte byte array of specified length.
static long toLong(byte[] byteArray, int offset, int len)
          This method constructs a long from a LSByte byte array of specified length.
static long toLong(String strData)
          Converts a hex-encoded string (LSByte) into a long.
static String toString(double dubbel, int nFrac)
          Converts a double value into a string with the specified number of digits after the decimal place.
static String toString(float flote, int nFrac)
          Converts a float value into a string with the specified number of digits after the decimal place.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toFahrenheit

public static final double toFahrenheit(double celsiusTemperature)
Converts a temperature reading from Celsius to Fahrenheit.
Parameters:
celsiusTemperature - temperature value in Celsius
Returns:
the Fahrenheit conversion of the supplied temperature

toCelsius

public static final double toCelsius(double fahrenheitTemperature)
Converts a temperature reading from Fahrenheit to Celsius.
Parameters:
fahrenheitTemperature - temperature value in Fahrenheit
Returns:
the Celsius conversion of the supplied temperature

toLong

public static final long toLong(byte[] byteArray,
                                int offset,
                                int len)
This method constructs a long from a LSByte byte array of specified length.
Parameters:
byteArray - byte array to convert to a long (LSByte first)
offset - byte offset into the array where to start to convert
len - number of bytes to use to convert to a long

toLong

public static final long toLong(byte[] byteArray)
This method constructs a long from a LSByte byte array of specified length. Uses 8 bytes starting at the first index.
Parameters:
byteArray - byte array to convert to a long (LSByte first)

toByteArray

public static final void toByteArray(long longVal,
                                     byte[] byteArray,
                                     int offset,
                                     int len)
This method constructs a LSByte byte array with specified length from a long.
Parameters:
longVal - the long value to convert to a byte array.
byteArray - LSByte first byte array, holds bytes from long
offset - byte offset into the array
len - number of bytes to get

toByteArray

public static final void toByteArray(long longVal,
                                     byte[] byteArray)
This method constructs a LSByte byte array with 8 bytes from a long.
Parameters:
longVal - the long value to convert to a byte array.
byteArray - LSByte first byte array, holds bytes from long

toByteArray

public static final byte[] toByteArray(long longVal)
This method constructs a LSByte byte array with 8 bytes from a long.
Parameters:
longVal - the long value to convert to a byte array.

toInt

public static final int toInt(byte[] byteArray,
                              int offset,
                              int len)
This method constructs an int from a LSByte byte array of specified length.
Parameters:
byteArray - byte array to convert to an int (LSByte first)
offset - byte offset into the array where to start to convert
len - number of bytes to use to convert to an int

toInt

public static final int toInt(byte[] byteArray)
This method constructs an int from a LSByte byte array of specified length. Uses 4 bytes starting at the first index.
Parameters:
byteArray - byte array to convert to an int (LSByte first)

toByteArray

public static final void toByteArray(int intVal,
                                     byte[] byteArray,
                                     int offset,
                                     int len)
This method constructs a LSByte byte array with specified length from an int.
Parameters:
intVal - the int value to convert to a byte array.
byteArray - LSByte first byte array, holds bytes from int
offset - byte offset into the array
len - number of bytes to get

toByteArray

public static final void toByteArray(int intVal,
                                     byte[] byteArray)
This method constructs a LSByte byte array with 4 bytes from an int.
Parameters:
intVal - the int value to convert to a byte array.
byteArray - LSByte first byte array, holds bytes from long

toByteArray

public static final byte[] toByteArray(int intVal)
This method constructs a LSByte byte array with 4 bytes from an int.
Parameters:
longVal - the long value to convert to a byte array.

toByteArray

public static final byte[] toByteArray(String strData)

Converts a hex-encoded string into an array of bytes.

To illustrate the rules for parsing, the following String:
"FF 0 1234 567"
becomes:
byte[]{0xFF,0x00,0x12,0x34,0x56,0x07}

Parameters:
strData - hex-encoded numerical string
Returns:
byte[] the decoded bytes

toByteArray

public static final int toByteArray(String strData,
                                    byte[] bData)

Converts a hex-encoded string into an array of bytes.

To illustrate the rules for parsing, the following String:
"FF 0 1234 567"
becomes:
byte[]{0xFF,0x00,0x12,0x34,0x56,0x07}

Parameters:
strData - hex-encoded numerical string
bData - byte[] which will hold the decoded bytes
Returns:
The number of bytes converted

toByteArray

public static final int toByteArray(String strData,
                                    byte[] bData,
                                    int offset,
                                    int length)

Converts a hex-encoded string into an array of bytes.

To illustrate the rules for parsing, the following String:
"FF 0 1234 567"
becomes:
byte[]{0xFF,0x00,0x12,0x34,0x56,0x07}

Parameters:
strData - hex-encoded numerical string
bData - byte[] which will hold the decoded bytes
offset - the offset into bData to start placing bytes
length - the maximum number of bytes to convert
Returns:
The number of bytes converted

toHexString

public static final String toHexString(byte[] data)
Converts a byte array into a hex-encoded String, using the provided delimeter.
Parameters:
data - The byte[] to convert to a hex-encoded string
Returns:
Hex-encoded String

toHexString

public static final String toHexString(byte[] data,
                                       int offset,
                                       int length)
Converts a byte array into a hex-encoded String, using the provided delimeter.
Parameters:
data - The byte[] to convert to a hex-encoded string
offset - the offset to start converting bytes
length - the number of bytes to convert
Returns:
Hex-encoded String

toHexString

public static final String toHexString(byte[] data,
                                       String delimeter)
Converts a byte array into a hex-encoded String, using the provided delimeter.
Parameters:
data - The byte[] to convert to a hex-encoded string
delimeter - the delimeter to place between each byte of data
Returns:
Hex-encoded String

toHexString

public static final String toHexString(byte[] data,
                                       int offset,
                                       int length,
                                       String delimeter)
Converts a byte array into a hex-encoded String, using the provided delimeter.
Parameters:
data - The byte[] to convert to a hex-encoded string
offset - the offset to start converting bytes
length - the number of bytes to convert
delimeter - the delimeter to place between each byte of data
Returns:
Hex-encoded String

toHexString

public static final String toHexString(byte bValue)

Converts a single byte into a hex-encoded string.

Parameters:
bValue - the byte to encode
Returns:
String Hex-encoded String

toHexString

public static final String toHexString(char[] data)
Converts a char array into a hex-encoded String, using the provided delimeter.
Parameters:
data - The char[] to convert to a hex-encoded string
Returns:
Hex-encoded String

toHexString

public static final String toHexString(char[] data,
                                       int offset,
                                       int length)
Converts a byte array into a hex-encoded String, using the provided delimeter.
Parameters:
data - The char[] to convert to a hex-encoded string
offset - the offset to start converting bytes
length - the number of bytes to convert
Returns:
Hex-encoded String

toHexString

public static final String toHexString(char[] data,
                                       String delimeter)
Converts a char array into a hex-encoded String, using the provided delimeter.
Parameters:
data - The char[] to convert to a hex-encoded string
delimeter - the delimeter to place between each byte of data
Returns:
Hex-encoded String

toHexString

public static final String toHexString(char[] data,
                                       int offset,
                                       int length,
                                       String delimeter)
Converts a char array into a hex-encoded String, using the provided delimeter.
Parameters:
data - The char[] to convert to a hex-encoded string
offset - the offset to start converting bytes
length - the number of bytes to convert
delimeter - the delimeter to place between each byte of data
Returns:
Hex-encoded String

toHexString

public static final String toHexString(char bValue)

Converts a single character into a hex-encoded string.

Parameters:
bValue - the byte to encode
Returns:
String Hex-encoded String

toLong

public static final long toLong(String strData)

Converts a hex-encoded string (LSByte) into a long.

To illustrate the rules for parsing, the following String:
"FF 0 1234 567 12 03"
becomes:
long 0x03120756341200ff

Parameters:
strData - hex-encoded numerical string
Returns:
the decoded long

toHexString

public static final String toHexString(long lValue)

Converts a long into a hex-encoded string (LSByte).

Parameters:
lValue - the long integer to encode
Returns:
String Hex-encoded String

toInt

public static final int toInt(String strData)

Converts a hex-encoded string (LSByte) into an int.

To illustrate the rules for parsing, the following String:
"FF 0 1234 567 12 03"
becomes:
long 0x03120756341200ff

Parameters:
strData - hex-encoded numerical string
Returns:
the decoded int

toHexString

public static final String toHexString(int iValue)

Converts an integer into a hex-encoded string (LSByte).

Parameters:
iValue - the integer to encode
Returns:
String Hex-encoded String

toString

public static final String toString(double dubbel,
                                    int nFrac)

Converts a double value into a string with the specified number of digits after the decimal place.

Parameters:
dubbel - the double value to convert to a string
nFrac - the number of digits to display after the decimal point
Returns:
String representation of the double value with the specified number of digits after the decimal place.

toString

public static final String toString(float flote,
                                    int nFrac)

Converts a float value into a string with the specified number of digits after the decimal place.

Note: this function does not properly handle special case float values such as Infinity and NaN.

Parameters:
flote - the float value to convert to a string
nFrac - the number of digits to display after the decimal point
Returns:
String representation of the float value with the specified number of digits after the decimal place.


Copyright © 1999-2003 Dallas Semiconductor. All Rights Reserved.