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