COUT bits from integer (Modified from others version)

Posted: March 13, 2012 in OOP344

This is modified & compacted version from Balwinder, XLIAN3 and Gulnaz codes.

Thank you!!

char*  bits(int val){
  static char str[sizeof(int)*8+1];
  for(int size=sizeof(int)*8; size; val>>=1){
    str[--size]= (val & 1) + 48;
  }
  str[sizeof(int)*8]=0;
  return str;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s