this routine will extract k msb's and will print them

n is the number,,
and k is the no of bits u wnt to print..
void k_msb(int n, int k)
{
     int mask;
     int count=0;
     int r;

     for(int i=31;i>=0;i--)
     {
         if(count==k)
         break;
         mask=1<<i;
         r=mask&n;
         r==0?cout<<"0":cout<<"1";
         count++;

      }

  }

On Sat, Aug 13, 2011 at 5:21 PM, Mohit Goel <[email protected]>wrote:

>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to