39 lines
794 B
C++
39 lines
794 B
C++
|
/*************************************************************************
|
||
|
> File Name : test_bit.cpp
|
||
|
> Author : TL Song
|
||
|
> EMail : songtianlun@frytea.com
|
||
|
> Created Time : Wed 05 Aug 2020 11:21:47 PM CST
|
||
|
************************************************************************/
|
||
|
|
||
|
#include <iostream>
|
||
|
#include <stdio.h>
|
||
|
|
||
|
#define getbit(x,y) ((x) >> (y)&1)
|
||
|
|
||
|
using std::cout;
|
||
|
using std::endl;
|
||
|
|
||
|
void printbit(int bit)
|
||
|
{
|
||
|
cout << "------------------------------------" << endl;
|
||
|
for(int i=0;i<9;i++)
|
||
|
{
|
||
|
printf("bit[%d]:%d\n",i,getbit(bit,i));
|
||
|
}
|
||
|
cout << "------------------------------------" <<endl;
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
int bit = 0;
|
||
|
for(int i=0;i<9;i++)
|
||
|
{
|
||
|
bit |= 1<<i;
|
||
|
cout << bit << endl;
|
||
|
printbit(bit);
|
||
|
}
|
||
|
|
||
|
|
||
|
return 0;
|
||
|
}
|