Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1605610
  • 博文数量: 695
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 4027
  • 用 户 组: 普通用户
  • 注册时间: 2013-11-20 21:22
文章分类

全部博文(695)

文章存档

2018年(18)

2017年(74)

2016年(170)

2015年(102)

2014年(276)

2013年(55)

分类: C/C++

2014-05-25 07:32:15


点击(此处)折叠或打开

  1. #include <stdio.h>

  2. #define Bit3 (0X01<<3)
  3. /*对一个数的第三位进行清零、置位、取反*/
  4. int main()
  5. {
  6.     int a=15 ; // 0000 1111

  7.     printf("原大小:%d\n", a);

  8.     a &= ~Bit3; //清零, 0000 0111
  9.     printf("清零后:%d\n", a);

  10.     a |= Bit3; //置位, 0000 1111
  11.     printf("置位后:%d\n", a);

  12.     a ^= Bit3; //取反, 0000 0111
  13.     printf("取反后:%d\n", a);

  14.     return 0;
  15. }
http://blog.csdn.net/yuliu0552/article/details/6820472

位操作,倒序输出,8位数据

点击(此处)折叠或打开

  1. #include <stdio.h>
  2. /*位操作,倒序输出,8位数据*/
  3. unsigned long BitReverse32(unsigned long number)
  4. {
  5.     unsigned long res = 0;
  6.     int i;
  7.     for(i = 1; i <= 8; i++)
  8.     {
  9.        res |= (number&1) << (8-i);
  10.        number >>= 1;
  11.     }
  12.     return res;
  13. };

  14. int main()
  15. {
  16.     int a = 19; // 0001 0011
  17.     int res = BitReverse32(a);
  18.     printf("%d\n", res); // 1100 1000
  19.     return 0;
  20. }


阅读(1546) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~