65,211
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
int main()
{
char nIn,nTemp;
cout<<"Before:"<<endl;
cin>>nIn;
for(int i=0;i<8;i++)
{
nTemp|=(((nIn>>(7-i))&0x01)<<(7-i));
}
cout<<"After:"<<nTemp;
return 0;
}
#include<iostream>
using namespace std;
typedef unsigned char byte;
void ShowBit(byte x, int n)
{
if (--n)
{
ShowBit(x>>1, n);
}
//printf("%d", x%2);
cout<<x%2;
}
void ReverseBit(byte* pValue)
{
byte bytmp = * pValue;
byte byvalue = 0;
int n = 0;
while(n<8)
{
if(bytmp & (0x1<<n) )
{
byvalue|=0x1<<(7-n);
}
n++;
}
*pValue = byvalue;
}
int main()
{
char nIn=0,nTemp=0;
cout<<"Before:"<<endl;
cin>>nIn;
ShowBit(nIn,8);
cout<<endl;
/*for(int i=0;i<8;i++)
{
nTemp|=(((nIn>>(7-i))&0x01)<<(7-i));
}*/
ReverseBit((byte*)&nIn);
cout<<"After:"<<endl;
ShowBit(nIn,8);
return 0;
}
#include<iostream>
using namespace std;
int main()
{
char nIn,nTemp;
cout<<"Before:"<<endl;
cin>>nIn;
for(int i=0;i<8;i++)
{
nTemp|=(((nIn>>(7-i))&0x01)<<(7-i));
}
cout<<"After:"<<nTemp;
return 0;
}