C# bitwise shift on ushort (UInt16)

淺唱寂寞╮ 提交于 2020-01-03 08:14:12

问题


I need to perform a bitwise 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?


回答1:


Cast the resulting value back into ushort after shifting:

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


来源:https://stackoverflow.com/questions/3819593/c-sharp-bitwise-shift-on-ushort-uint16

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!