how about this....
n+(8-(n&7))

On Sun, Sep 26, 2010 at 4:48 AM, Dave <dave_and_da...@juno.com> wrote:

> @Ashwath: Thanks for the correction.
>
> Dave
>
> On Sep 26, 1:20 am, aswath G B <aswat...@gmail.com> wrote:
> > @Dave
> >
> >  Slight change u have to do
> >
> > #include<stdio.h>
> > main()
> > {
> >  int a = 24;
> >  int b = (a | 7)+1;  //This Line U have to change.....& not  a || 7.....
> >  printf("%d",b);
> >  return 0;
> >
> > }
> >
> > tats it....
> >
> > btw it is nice one line easy soln...
> >
> >
> >
> >
> >
> > On Sat, Sep 25, 2010 at 10:17 PM, Dave <dave_and_da...@juno.com> wrote:
> > > answer = (x || 7) + 1;
> >
> > > Dave
> >
> > > On Sep 25, 6:56 am, Krunal Modi <krunalam...@gmail.com> wrote:
> > > > Q: Write an algorithm to compute the next multiple of 8 for a given
> > > > positive integer using bitwise operators.
> >
> > > > Example,
> > > > (a) For the number 12, the next multiple of 8 is 16.
> > > > (b) For the number 16, the next multiple of 8 is 24.
> > > > -------------------------
> > > > I have written a code using bitwise operators...but, I am not happy
> > > > with the solution....Is there any ONE LINE solution ?
> > > > Here, is my code.
> > > > Approach: shift left till LSB is 0 (say n number of times) then, OR
> > > > with 1, finally shift right (same number of times).
> >
> > > > #include<stdio.h>
> >
> > > > int main(){
> > > >         int count,m,n,ans,t;
> >
> > > >         printf("Enter any number :");
> > > >         scanf("%d",&n);
> >
> > > >         m=8; //multiple of 8 !!
> > > >         ans=0;
> > > >         while(ans<=n){
> > > >                 t = m;
> > > >                 while(t){
> > > >                         count=0;
> > > >                         while(ans&1){
> > > >                                 count++;
> > > >                                 ans = ans>>1;
> > > >                         }
> > > >                         ans = ans|1;
> > > >                         ans = ans<<count;
> > > >                         t--;
> > > >                 }
> > > >         }
> >
> > > >         printf("[%d]\n",ans);
> >
> > > >         return 0;
> >
> > > > }- Hide quoted text -
> >
> > > > - Show quoted text -
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to algoge...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> <algogeeks%2bunsubscr...@googlegroups­.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.
> >
> > --http://aswath78.blogspot.com- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
S.Nishaanth,
Computer Science and engineering,
IIT Madras.

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

Reply via email to