开发者

C# bitwise shift on ushort (UInt16)

开发者 https://www.devze.com 2023-01-17 20:55 出处:网络
I need to perform a bit开发者_C百科wise left shift on a 16-bit integer (ushort / UInt16), but the bitwise operators in C# seem to apply to int (32-bit) only. How can I use << on an ushort, or at

I need to perform a bit开发者_C百科wise left shift on a 16-bit integer (ushort / UInt16), but the bitwise operators in C# seem to apply to int (32-bit) only. How can I use << on an ushort, or at least get to the same result with a simple workaround?


Cast the resulting value back into ushort after shifting:

ushort value = 1;
ushort shifted = (ushort)(value << 2);
0

精彩评论

暂无评论...
验证码 换一张
取 消