On Mon, 07 May 2007 15:09:20 -0700, Star <st**@nospam.comwrote:
[...]
'Res' needs to be the concatenation of all those bytes.
I mean, it should be something like
Res = 0x04F1B4
which converted to integer is 324020.
On the other hand, buffer can contain any number of bytes,not only 3
(I know the length)
Pedantic mode: obviously the buffer cannot contain *any* number of bytes..
It has to be within the range of the number of bytes used to represent the
destination type. :)
Anyway, that said, as an example of how you might use the BitConverter
class that Jon mentioned:
static public int Convert(byte[] rgbInput)
{
byte[] rgbWork = new byte[4];
if (rgbInput.Length rgbWork.Length)
{
throw new ArgumentOutOfRangeException("Maximum length of
rgbInput is " + rgbWork.Length);
}
rgbInput.CopyTo(rgbWork, 0);
return BitConverter.ToInt32(rgbWork, 0);
}
Note that the code assumes your destination type is in fact an int, and
that the data is little-endian. The example you gave actually shows
big-endian data. To handle big-endian, you might add this line just
before the one calling the CopyTo() method:
Array.Reverse(rgbInput);
Hope that helps.
Pete