码迷,mamicode.com
首页 > 其他好文 > 详细

整型数字按位取

时间:2017-06-02 19:37:11      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:content   article   post   i++   print   sys   pause   ==   window   

#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;
}

整型数字按位取

标签:content   article   post   i++   print   sys   pause   ==   window   

原文地址:http://www.cnblogs.com/yxysuanfa/p/6934803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!