博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
左移运算符
阅读量:4450 次
发布时间:2019-06-07

本文共 1432 字,大约阅读时间需要 4 分钟。

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  or a type that has a predefined implicit numeric conversion to int.

 

Remarks

If the first operand is an  or  (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  or  (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 ); 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];

需要这么转换,否则存在数据位丢失的问题

 

转载于:https://www.cnblogs.com/chucklu/p/4819251.html

你可能感兴趣的文章
树链剖分总结笔记
查看>>
hdu 4043
查看>>
hdu 1506
查看>>
PowerShell创建 Profile
查看>>
MySQL+Altas 读写分离测试(Altas 不能用存储过程,Update和Delete必须要有参数)
查看>>
Spring声明式事务管理基于tx/aop命名空间
查看>>
元素float以后,div高度无法自适应解决方案
查看>>
redis持久化 RDB和AOF
查看>>
回到顶部按钮
查看>>
HTML5的新结构标签
查看>>
非windows下 php连接mssql FreeTDS配置
查看>>
面试技术资料收藏
查看>>
RedHat Enterprise Linux 5下安装JDK
查看>>
合理的代码覆盖率
查看>>
【转】2014区域赛小结(牡丹江&&鞍山)by kuangbin
查看>>
光标跟随
查看>>
2/24笔记
查看>>
纯真的间谍
查看>>
paramiko上传下载
查看>>
【转】C#各个版本中的新增特性详解
查看>>