zoukankan      html  css  js  c++  java
  • 左移运算符

    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];

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

  • 相关阅读:
    linux历史及基本知识
    this关键字
    类加载与对象初始化
    学习之vim
    简单的登录界面(包括帐号密码验证)
    Web前端基础
    九大排序算法
    对“面向对象”思想的理解
    交换机
    网络编程协议详解
  • 原文地址:https://www.cnblogs.com/chucklu/p/4819251.html
Copyright © 2011-2022 走看看