#include <cstdio>
#include<iostream>
using namespace std;
char* bits(int val){
const int m = sizeof(int)*8;
static char str[m];
int i;
int j;
for(i = m-1, j = 0; i>=0;i--,j++){
if(val & (1<<i))
str[j] = '1';
else
str[j] = '0';
}
return str;
}
int main () {
int i = 2345;
cout << " i: " << bits(i) << endl;
return 0;
}
No comments:
Post a Comment