Yi's Blog

返回一字节中某一位的值

2013-09-16

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;

bool bit(char c,int num)//返回c的第num(0~7)位的值
{
cout<< ((c&(1<<num))>>num)<<endl;
return (c&(1<<num))>>num;
}

int main()
{
char a=6;
for(int i=0;i<8;i++)
bit(a,i);
return 0;
}
Tags: C++