zoukankan      html  css  js  c++  java
  • C位移操作

       1: #include <stdio.h>
       2:  
       3: main () {
       4:     int a = 1;
       5:     unsigned b = 1;
       6:  
       7:     int c = -1;
       8:     char d = 'a';
       9:  
      10:     printf("%d\n", d);
      11:     printf("%d\n", 'A');
      12:  
      13:     a = a<<1;
      14:     b = b<<1;
      15:     c = c<<1;
      16:     d = d<<1; // a is decimal 97, bin 1100001
      17:  
      18:     printf("%d\n", a);
      19:     printf("%d\n", b);
      20:     printf("%d\n", c);
      21:     printf("%d\n", d);
      22:  
      23:  
      24: }

    输出:

    image

    1.  不管是左移还是右移,如果操作数为无符号数,则填充字段为0;如果操作数为有符号数,填充字段为编译器自定义,有可能为0,也有可能为符号比特。

    2. 负数在内存中以补码形式表示,以变量d为例,a的二进制数为1100001,左移一位后为11000010,为十进制数62的补码形式。具体的说 11000010取反加一后为整数62的表示形式,所以11000010为-62.

  • 相关阅读:
    Fragment入门代码
    Handler注意事项
    Handler处理消息
    Handler发送消息
    Hander创建消息
    handler四元素
    handler方法
    Handle的特点
    handler定义
    9Patch图
  • 原文地址:https://www.cnblogs.com/dracohan/p/3011677.html
Copyright © 2011-2022 走看看