整型数字按位取

来源:互联网 发布:客户管理crm软件 编辑:程序博客网 时间:2024/06/11 08:08
#include "stdafx.h"
#include <windows.h>
void countone2(int N)
{
int a = N;
int count = 0;
int b ;
for (int i=0;i<32;i++)
{
b = (a>>i)&0x01;
printf("%d ",b);
if (1 == b)
{
count ++;
}
}
printf("\n二进制总共有%d个‘1’\n",count);
}
void gethorl()
{
unsigned int test = 255;
unsigned int test_h = (test>>16)&0xffff;
unsigned int test_l = test&0xffff; 
printf("%u %u\n",test_l,test_h);
}
void low_high()
{
int a = 250;
byte low8a = (a<<8)>>8;//低8位
byte high8a = a>>8;//高8位
printf("%u %u\n",low8a,high8a);
}
int _tmain(int argc, _TCHAR* argv[])
{
countone2(255);
gethorl();
low_high();
system("pause");
return 0;
}
0 0
原创粉丝点击