Discussion:
Debugging Bits
(too old to reply)
Randy
2007-11-19 18:55:07 UTC
Permalink
unsigned long a = 1

I watch "a"
It comes out as expected. 1

I watch "~a"
It comes out with crap when I was expecting 0.

Thanx for wading through all the spam to find this post !
Nathan Mates
2007-11-19 19:13:51 UTC
Permalink
Post by Randy
unsigned long a = 1
I watch "a"
It comes out as expected. 1
I watch "~a"
It comes out with crap when I was expecting 0.
You may want to consider reading up in a C/C++ manual as to what
the various operations do. '!a' is the logical inverse, which seems to
be what you want. '~a' is the bitwise inverse, which flips all bits.

Nathan Mates

--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein
Randy
2007-11-19 20:47:05 UTC
Permalink
Thanx Nathan

cout << "Bitwise" << endl;

enum {
Ready = 1 << 0,
Willing = 1 << 1
};

cout << Ready << endl;
cout << ~Ready << endl;
cout << !Ready << endl;

Bi
1
-2
0

I ran a test and of course you are right, meaning this thread is now
off-topic. Forgive my newbness but I was forgetting that the number
gets recombined into decimal, giving me a "whacked *decimal*" result
instead of the binary I was expecting.

Loading...