C++入门经典-例2.14-使用移位运算

1:代码如下:

C++入门经典-例2.14-使用移位运算C++入门经典-例2.14-使用移位运算
// 2.14.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
using namespace std;
void main()
{
    long nWord=0x12345678;//长整形,十六进制输入
    int nBits;
    nBits=nWord & 0xFFFF;//位与
    printf("low bits are 0x%x\n",nBits);//十六进制输出,输出低4位
    nBits=(nWord & 0xFFFF0000)>>16;
    printf("hight bits is 0x%x\n",nBits);//十六进制输出,输出高4位
}
/*十六进制向右移n位,则二进制向右以2的n次方位*/
View Code

运行结果:

C++入门经典-例2.14-使用移位运算

posted @ 2017-09-11 18:35 一串字符串 阅读(...) 评论(...) 编辑 收藏

相关文章:

  • 2021-06-14
  • 2021-08-29
  • 2021-06-15
  • 2021-06-30
  • 2021-09-04
  • 2021-05-27
  • 2021-07-19
猜你喜欢
  • 2021-05-04
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
相关资源
相似解决方案