C# How to store bytes into Uint32 array

127 Views Asked by At

I have an UINT32 array filled with bytes, because my value is too long it has to be in uint32 because byte array is just to short for it

UInt32[] somebytes = new UInt32[] { 0xAABBCC, 0xAABBCC };

but whats inside is 0x00AABBCC, 0x00AABBCC

and because of that my function that should return first 2 bytes in every row

[0] = 0xAA
[1] = 0xAA

returns

[0] = 0x00
[1] = 0x00

here is my function, that should return first 2 bytes (my brain tells me that first 2 bytes are 0xAA)

public byte[] GetRed(UInt32[] buffer)
{
    byte[] output = new byte[buffer.Length];
    for (int i = 0; i < output.Length; i++)
    {
        byte b = (byte)buffer[i];
        output[i] = (byte)(b & 0xFFFF);   //fist 2 bytes
    }
    return output;
}

I hope someone has an idea, on whats going on and how to fix all this Thsnk

0

There are 0 best solutions below