左移运算符
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 anintor a type that has a predefined implicit numeric conversion toint.
Remarks
If the first operand is anintoruint(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 alongorulong(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 (seeoperator); the type of the first operand must be the user-defined type, and the type of the second operand must beint. When a binary operator is overloaded, the corresponding assignment operator, if any, is also implicitly overloaded.
左移運算符返回的值,默認是int的
Comments
Note thati<<1andi<<33give 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];
需要這么轉換,否則存在數據位丟失的問題
總結
- 上一篇: 笔记本安装显卡驱动黑屏是怎么回事笔记本安
- 下一篇: Nginx 搭建反向代理服务器过程详解