The following function takes an integer and returns the binary string:
constchar* bits(unsignedint val){unsignedint m =1<<sizeof(val)*8-1;char* str =newchar[sizeof(val)*8+1];int i =0;while(m){
str[i]=(val & m)?'1':'0';
i++;
m = m >>1;}
str[i]=0;return str;}
No comments:
Post a Comment