A Agr wrote:Store hexadecimal nos in either String[] or String or int[].
for ex : String[] s = {"0x09","0x800"}
or int[] i ={0x09,0x800};
Now I want to convert it to byte array to write to an OutputStream. If I do String.getBytes() ,it encodes.
But what I want is my InputStream to read the byte array I send as
byte array containing 090800
1. String.getBytes() returns the ASCII values of the string as a byte array. This is not what you want.
2. For the int array, if you use the ByteBuffer class, it will probably do it incorrectly (not sure, haven't used all the features) as it assumes all integers are 4 bytes. So....
int[] i ={0x09,0x800};
should be converted to...
byte[] b = {0x00, 0x00, 0x00, 0x09,0x00, 0x00, 0x08, 0x00};
3. If you do it manually. Create the byte buffer, and shift the int values into place, it should work. Or use the ByteBuffer class, and remove the parts you don't want, that will work too.
Henry