此代码仅在字节数等于 1 时有效,我想打印用户从命令行插入的内容,并且稍后可以更改字节数
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
void writeToScreen(char *data);
const int NOBYTES = 2;
int main(int argc, char *argv[]){
// Example input is: FFA6 (2 Bytes)
writeToScreen(argv[1]);
system("pause");
return 0;
}
void writeToScreen(char *data){
for(int j=0;j<NOBYTES;j++){
unsigned char dat = strtol(data+NOBYTES-j-1, NULL, 16);
for (unsigned int i=0;i<8;i++)
{
if (dat & 1)
cout<<"1";
else
cout<<"0";
dat>>=1;
}
cout<<endl;
}
}
/*
Can i get the out put to be (FFA6):
11111111
10100110
*/