how do i write this

P

Pascal J. Bourguignon

M.Manjunatha said:
How do i write this in a simple fashion?? (a & b) ! = b

This is not legal C or C++ syntax.

The ! operator is not a post-operator but a prefix operator.
An expression is not a valid l-value for the = operator.

But supposing you meant (a&b)!=b, how simplier do you imagine it could become?
You can always introduce function abstractions (and I'd advise you to do so),
but is it really simplier?

This expression test whether b has set any bit not set in a.

That is, considering a and b to represent sets of small integers,
whether b is a strict superset of a,
ie. whether b is not a subset of a.

So you could abstract the expression away as:

bool is_strict_superset_of(int super,int set){ return((set & super) != super); }
// or:
bool is_not_subset_of(int sub,int set){ return((set & sub) != sub); }


Is is_strict_superset_of(b,a) simplier than (a&b)!=b ?
I think so, but do you agree?
 
A

alasham.said

( a & b ) != b
=> [( a & b ) & !b ] | [!( a & b ) & b ]
=> [ ( a & !b ) & ( b & !b ) ] | [( !a | !b ) & b ]
=> [ ( a & !b ) & F ] | [ ( !a & b ) | ( !b & b ) ]
=> [ F ] | [ ( !a & b ) | F ]
=> [ ( !a & b ) | F ]
=> !a & b

But this is more
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,226
Latest member
KristanTal

Latest Threads

Top