1. 程式人生 > >整型數字按位取

整型數字按位取

signed one span post count pac -s div i++

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

整型數字按位取