JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
<< PREV    [ 1 2 ]
Re: Checking if a number is a power of two (response to post by Kawigi) | Reply
Isn't adding 1 after inverting the same as subtracting one before inverting?

Doh! Of course is it. Please ignore my claim that i & -i tells you whether i is one less than a power of 2.
Re: Checking if a number is a power of two (response to post by kyky) | Reply
It is also possible to iterate over all the subsets of a particular subset (represented by a bit pattern), provided that you don't mind visiting them in reverse order (if this is problematic, put them in a list as they're generated, then walk the list backwards).

Why not just use (superset - i) instead of i wherever you need the subset, if you need them in increasing order?
Re: Checking if a number is a power of two (response to post by dskloet) | Reply
i would like bitset to have +, -, *, / operators, they would help a lot :(.

Is there a way to know if there is carry without using assembler???
Re: Checking if a number is a power of two (response to post by dskloet) | Reply
Neat idea, as a slight improvement I would go for (superset ^ i) here, same output, different instruction ;) [just one bitwise operation, no arithmetics done]
Re: Checking if a number is a power of two (response to post by rserranop) | Reply
Is there a way to know if there is carry without using assembler???

If a and b are unsigned ints, then a + b will overflow if
a > UINT_MAX - b
Of course, assembler will be faster.
Re: Checking if a number is a power of two (response to post by kyky) | Reply
Would someone please tell me help to prove x&(x-1) ?
How to deal with x -1 ? I don't know to to use Demorgan and Distributive property over that.

Many thanks.
<< PREV    [ 1 2 ]

RSS