0

i do have an byte array included a range of numbers...

t Block and not the rest!

How can i have all block 4-8 in Temp[] ??

1 Answers1

2

Elements 4-8 (or in reality index 3-7) is 5 bytes. Not 4.
You have the source offset and count mixed up:

Buffer.BlockCopy(bResponse, 3, temp, 0, 5);

Now temp will contain [23232].

If you want the last 4 bytes then use this:

Buffer.BlockCopy(bResponse, 4, temp, 0, 4);

Now temp will contain [3232].
To convert this to an int:

if (BitConverter.IsLittleEndian)
  Array.Reverse(temp);

int i = BitConverter.ToInt32(temp, 0);

Edit: (After your comment that [43323232] actually is {43, 32, 32, 32})

var firstByte = temp[0];   // This is 43
var secondByte = temp[1];  // This is 32
var thirdByte = temp[2];   // 32
var fourthByte = temp[3];  // 32

If you want to convert this to an int then the BitConverter example above still works.

Sani Huttunen
  • 23,620
  • 6
  • 72
  • 79
  • This is not the Answer! This one its only to take 3 block from buffer how you want to assign this 3 in one Temp[]? – Alexandera MacQueen Dec 18 '12 at 09:24
  • Each of this have to read individually and sort in Temp back to back with your method is nothing but only reading 4bytes. I have no problem for reading the problem is assigning this 4 in another Array i call Temp[] – Alexandera MacQueen Dec 18 '12 at 09:27
  • @Artinos: You are wrong about the number of bytes read. If you read the MSDN page of [Buffer.BlockCopy](http://msdn.microsoft.com/en-us/library/system.buffer.blockcopy.aspx) you'll see that it is you who have mixed up the `source offset` and `count` parameters. – Sani Huttunen Dec 18 '12 at 09:33
  • You are Right about the Number My bad in Typing ...However i still cannot Put put the 3 byte block into one block called Temp[] – Alexandera MacQueen Dec 18 '12 at 09:37