com.rapplogic.xbee.util
Class ByteUtils

java.lang.Object
  extended by com.rapplogic.xbee.util.ByteUtils

public class ByteUtils
extends java.lang.Object


Method Summary
static int[] convertInttoMultiByte(int val)
          Works for positive values only
static int convertMultiByteToInt(int[] bytes)
          There is a slight problem with this method that you might have noticed; a Java int is signed, so we can't make use of the 32nd bit.
static java.lang.String formatByte(int b)
           
static boolean getBit(int b, int position)
          Returns true if the bit is on (1) at the specified position Position range: 1-8
static int parse10BitAnalog(IIntInputStream in, int pos)
           
static int parse10BitAnalog(int msb, int lsb)
          Parses a 10-bit analog value from the input stream
static int[] stringToIntArray(java.lang.String s)
           
static java.lang.String toBase10(int[] arr)
           
static java.lang.String toBase16(int b)
           
static java.lang.String toBase16(int[] arr)
           
static java.lang.String toBase16(int[] arr, java.lang.String delimiter)
           
static java.lang.String toBase2(int b)
           
static java.lang.String toBase2(int[] arr)
           
static java.lang.String toChar(int[] arr)
          Deprecated. use toString(int[] arr)
static java.lang.String toString(int[] arr)
          Converts an int array to string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

convertMultiByteToInt

public static int convertMultiByteToInt(int[] bytes)
There is a slight problem with this method that you might have noticed; a Java int is signed, so we can't make use of the 32nd bit. This means this method does not support a four byte value with msb greater than 01111111 ((2^7-1) or 127) and will throw a runtime exception if it encounters this situation. TODO use long instead of int to support 4 bytes values. note that long assignments are not atomic. Not Used


convertInttoMultiByte

public static int[] convertInttoMultiByte(int val)
Works for positive values only

Parameters:
val -
Returns:

toBase16

public static java.lang.String toBase16(int[] arr)

toBase16

public static java.lang.String toBase16(int[] arr,
                                        java.lang.String delimiter)

toBase2

public static java.lang.String toBase2(int[] arr)

toBase10

public static java.lang.String toBase10(int[] arr)

toChar

public static java.lang.String toChar(int[] arr)
Deprecated. use toString(int[] arr)


toString

public static java.lang.String toString(int[] arr)
Converts an int array to string. Note: this method does not validate that int values map to valid characters

Parameters:
arr -
Returns:

getBit

public static boolean getBit(int b,
                             int position)
Returns true if the bit is on (1) at the specified position Position range: 1-8


toBase16

public static java.lang.String toBase16(int b)

toBase2

public static java.lang.String toBase2(int b)

formatByte

public static java.lang.String formatByte(int b)

stringToIntArray

public static int[] stringToIntArray(java.lang.String s)

parse10BitAnalog

public static int parse10BitAnalog(int msb,
                                   int lsb)
                            throws java.io.IOException
Parses a 10-bit analog value from the input stream

Returns:
Throws:
java.io.IOException

parse10BitAnalog

public static int parse10BitAnalog(IIntInputStream in,
                                   int pos)
                            throws java.io.IOException
Throws:
java.io.IOException