#include <iostream>
using namespace std;
const char* bits(unsigned int val);
int main(){
char A = 0x5c;
char B = 0x95;
char C = 0;
cout<<bits(A)<<endl;
return 0;
}
const char* bits(unsigned int val){
int i = 0;
int j = '1' - 1; //The ascii value between char '1' and decimal 1
unsigned int m = 1 << sizeof(val)*8 - 1;
char* s = new char[sizeof(val)*8+1];
while(m){
s[i] = j + !!(m & val);
m = m >> 1;
i++;
}
s[i] = 0;
return s;
}
No comments:
Post a Comment