here for the next multiple of 8
i have 3 different solutions ...
1)...
nextmultiple = (n/8+1)*8
2)...
nextmultiple= n+(8-n%8)
3)...
suppose i have 32-bit compiler
for(i=32; i1; i--)
{
if((pow(2,i)n==0)(pow(2,i-1)n!=0))
{
@Arun: A multiple of 8 has three rightmost bits = 0. I first though
about anding out these bits and adding 8. Code for that would be
answer = (n (~7)) + 8.
Alternatively, round up. That you can do by adding 8 and then zeroing
out the low-order three bits. Code for that would be
answer = ((n +
how about this
n+(8-(n7))
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
#includestdio.h
main()
{
int a = 24;
#includeiostream
using namespace std;
int main()
{
int n,temp,ans=1;
cin n;
temp=n/8;
temp++;
cout hi temp\n;
while(temp--)
{
temp=temp3;
}
cout temp;
return 0;
}
--
You received this message because you are subscribed to the Google
@Dave
Slight change u have to do
#includestdio.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:
@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
#includestdio.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
Basically, I am starting from (ans=)0 checking if it has become
greater than n, if not repeat(means, add 8) else answer is found.
--
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.
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.
did u mean next multiple of 8 greater than given number(12 or 16). ?
On Sat, Sep 25, 2010 at 5:28 PM, Krunal Modi krunalam...@gmail.com wrote:
Basically, I am starting from
let the number be x .
solution = x - (x%8) + 8;
--
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
solution = ((x3) + 1)3;
On Sat, Sep 25, 2010 at 5:45 PM, Rahul Singal rahulsinga...@gmail.comwrote:
let the number be x .
solution = x - (x%8) + 8;
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
this wont work if x=24 i.e.multiple of 8
On Sep 25, 6:00 pm, Baljeet Kumar baljeetk...@gmail.com wrote:
solution = ((x3) + 1)3;
On Sat, Sep 25, 2010 at 5:45 PM, Rahul Singal rahulsinga...@gmail.comwrote:
let the number be x .
solution = x - (x%8) + 8;
--
You received this message
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
@rajess
It works for all the cases.
On Sat, Sep 25, 2010 at 8:42 PM, rajess rajess1...@yahoo.com wrote:
this wont work if x=24 i.e.multiple of 8
On Sep 25, 6:00 pm, Baljeet Kumar baljeetk...@gmail.com wrote:
solution = ((x3) + 1)3;
On Sat, Sep 25, 2010 at 5:45 PM, Rahul Singal
@Dave
very nice one line solution..
we all are revolving around x3 concept...
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
Simple one line solution without looping and efficient :
i=(i7)?(i|7)+1:i)
On Sun, Sep 26, 2010 at 8:43 AM, coolfrog$
dixit.coolfrog.div...@gmail.comwrote:
@Dave
very nice one line solution..
we all are revolving around x3 concept...
On Sat, Sep 25, 2010 at 10:17 PM, Dave
@Saurab: Nice solution
On Sun, Sep 26, 2010 at 11:27 AM, saurabh agrawal saurabh...@gmail.comwrote:
Simple one line solution without looping and efficient :
i=(i7)?(i|7)+1:i)
On Sun, Sep 26, 2010 at 8:43 AM, coolfrog$
dixit.coolfrog.div...@gmail.com wrote:
@Dave
very nice one line
16 matches
Mail list logo