Search code examples
c#copycastinguint32

Fastest way to cast int to UInt32 bitwise?


i have some low level image/texture operations where 32-bit colors are stored as UInt32 or int and i need a really fast bitwise conversion between the two.

e.g.

 int color = -2451337;  

 //exception
 UInt32 cu = (UInt32)color;

any ideas?

thanks and regards


Solution

  • int color = -2451337;
    unchecked {
        uint color2 = (uint)color;
        // color2 = 4292515959
    }