左移运算符
https://msdn.microsoft.com/en-us/library/a1sway8w.aspx
The left-shift operator (<<) shifts its first operand left by the number of bits specified by its second operand.
The type of the second operand must be an int or a type that has a predefined implicit numeric conversion to int.
Remarks
If the first operand is an int or uint (32-bit quantity), the shift count is given by the low-order five bits of the second operand. That is, the actual shift count is 0 to 31 bits.
If the first operand is a long or ulong (64-bit quantity), the shift count is given by the low-order six bits of the second operand. That is, the actual shift count is 0 to 63 bits.
Any high-order bits that are not within the range of the type of the first operand after the shift are discarded, and the low-order empty bits are zero-filled. Shift operations never cause overflows.
User-defined types can overload the << operator (see operator); the type of the first operand must be the user-defined type, and the type of the second operand must be int. When a binary operator is overloaded, the corresponding assignment operator, if any, is also implicitly overloaded.
左移运算符返回的值,默认是int的
Comments
Note that i<<1 and i<<33 give the same result, because 1 and 33 have the same low-order five bits.
举例,比如我有一个数字0x 11 22 33 44 55 66
现在需要转换成十进制的数字
var result = ((long)bytes[0]) << 40 | ((long)bytes[1]) << 32 | ((uint)bytes[2]) << 24 | (bytes[3]) << 16 | bytes[4] << 8 | bytes[5];
需要这么转换,否则存在数据位丢失的问题
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了