views:

134

answers:

3

Hello overflow,

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

+2  A: 
BitConverter.ToUInt32(BitConverter.GetBytes(-2451337), 0)
Jader Dias
+1 to offset the downvote. Even before my edit there was nothing of vital importance wrong with this answer. In fact, this would be the preferred method if using VB since direct casts from Int32 to UInt32 and granular unchecked contexts are not allowed.
Brian Gideon
supercat
+11  A: 
int color = -2451337;
unchecked {
    uint color2 = (uint)color;
    // color2 = 4292515959
}
Simon Svensson
nice! just what i was looking for.. thanks!!
thalm
A: 
supercat