Zakaria,
That is not the result I am seeking.
I want to convert from
one integer to a byte array and from a byte array to
one integer.
Example:
255 is equal to new byte(0x00,0xFF)
65535 is equal to new byte(0xFF, 0xFF)
Einar
>Hello Einar,
>
>I think You could use the copyto method of the array to another array with another cast. So for exmaple :
>
>
>
> System.Byte[] bValue = new System.Byte[10];
> System.Int32[] iValue = new System.Int32[10];
> bValue.CopyTo(iValue, 0);
>
>HTH
>
>Zakaria al Azhar
>
>
>>Is there an easy way to convert from a byte array to integer? Is there an equaly easy way to convert from integer to a byte array?
>>
>>Currently what I do for a byte array of length 2:
>>
>>System.Int32 iValue = 42000;
>>System.Byte[] bValue = new System.Byte[2];
>>
>>bValue[0] = Convert.ToByte(iValue/256);
>>bValue[1] = Convert.ToByte(iValue%256);
>>
>>System.Int32 iRetVal;
>>iRetVal = Convert.ToInt32(Convert.ToInt32(bValue[0]) * 256 + Convert.ToInt32(bValue[1]));
>>
>>
>>Now this isn't a lot of work for byte[2] but it will get kinda messy for byte[4]. I have got it working for byte[4], but I was wondering if there was a simpler/built in (one-liner) way of doing this.
>>
>>Any help would be appreciated.
>>
>>Thanks,
>>Einar
Semper ubi sub ubi.