public class bytechars { // Methods public static int byte2hex(byte[] b, int start, int length); §byte2hex public static int byte2int(byte[] b); §byte2int1 public static int byte2int(byte[] b, int start); §byte2int2 public static short byte2short(byte[] b, int start); §byte2short public static String byte2string(byte[] b); §byte2string1 public static String byte2string(byte[] b, int length); §byte2string2 public static String byte2string(byte[] b, int start, int length); §byte2string3 public static byte[] int2byte(int in); §int2byte1 public static byte[] int2byte(int[] in); §int2byte2 public static String readString(); §readString1 public static String readString(int length); §readString2 public static void short2byte(short s, byte[] array, int at); §short2byte public static void string2byte(String s, byte[] b, int start, int length); §string2byte }This class is an incomplete collection of conversion routines between byte arrays and strings and various integers.
public static String byte2hex(byte[] b, int start, int length)
b
-
the byte array to be converted to hexadecimal string
start
-
the position in the byte array where conversion is to start
length
-
the number of elements of the byte array to be converted
public static int byte2int(byte[] b)
b
-
the byte array to be converted to int (twos complement)
public static int byte2int(byte[] b, int start)
b
-
the byte array to be converted to int (twos complement)
start
-
the position in the byte array where conversion is to start
public static short byte2short(byte[] b, int start)
b
-
the byte array to be converted to short (twos complement)
start
-
the position in the byte array where conversion is to start
public static String byte2string(byte[] b)
b
-
the byte array to be converted to String: expects ascii
public static String byte2string(byte[] b, int length)
b
-
the byte array to be converted to String: expects ascii
length
-
the number of elements of the byte array to be converted
public static String byte2string(byte[] b, int start, int length)
b
-
the byte array to be converted to String: expects ascii
start
-
the position in the byte array where conversion is to start
length
-
the number of elements of the byte array to be converted
public static byte[] int2byte(int in)
in
-
the integer to be converted to byte array (twos complement)
public static byte[] int2byte(int[] in)
in
-
an array of integers to be converted to byte array (twos complement)
public static String readString()
public static String readString(int length)
length
-
the minimum length of the string returned
public static void short2byte(short s, byte[] array, int at)
s
-
the short to be converted to byte array (twos complement)
array
-
output: the byte array containing the result
at
-
the position in the output byte array where the converted short is to start
public static void string2byte(String s, byte[] b, int start, int length)
s
-
the string to be converted to byte array
b
-
output: the byte array containing the result
start
-
the position in the output byte array where the converted string is to start
length
-
the number of characters converted and. hence, bytes output