tha*_*alm 8 c# casting copy uint32
我有一些低级别的图像/纹理操作,其中32位颜色存储为UInt32或int,我需要在两者之间进行非常快速的按位转换.
例如
int color = -2451337;
//exception
UInt32 cu = (UInt32)color;
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
感谢致敬
sis*_*sve 21
int color = -2451337;
unchecked {
uint color2 = (uint)color;
// color2 = 4292515959
}
Run Code Online (Sandbox Code Playgroud)
BitConverter.ToUInt32(BitConverter.GetBytes(-2451337), 0)
Run Code Online (Sandbox Code Playgroud)