4 Replies Latest reply: Dec 11, 2006 3:57 AM by 807607

# help, converting integers to array of bytes

Hi, I have an array of integer as follows:

int[] values = {1, 2, 6, 13, 17}

byte 1 represent values 0 - 7
byte 2 represent values 8 - 15
etc..

I want to convert the above integer array to an array of byte.
I.e the array if byte represented in decimal should be like this

byte[0] = 70
byte[1] = 32
byte[2] = 2

Can anyone please show me how to achieve this
thanks in advance
• ###### 1. Re: help, converting integers to array of bytes
your question is not clear.

what do you mean by this:-
byte 1 represent values 0 - 7
byte 2 represent values 8 - 15
etc..
Reframe your question. what you actually what to do???
• ###### 2. Re: help, converting integers to array of bytes
From my array {1, 2, ,6 ,13, 17}, I want values 1,2 & 6 to be represented in the 1st first byte. Value 13 in the 2nd byte and value 17 in the 3rd byte
• ###### 3. Re: help, converting integers to array of bytes
And what is the abstract description of this conversion algorithm?

Mike
• ###### 4. Re: help, converting integers to array of bytes
you mean there will be 128/8 = 16, byte arrays,
byte[] b1, b2, b3.... b16;

and the numbers above 127 would be ignored.

am I right.

or you want to say something else.