Follow

@lore Zallen {0,1}.
Seemingly the negation of X and 1. Negation of X being the bit flip of the binary number. So it's going to be swapping to truth value and adding a 1 to it. It could return the same value or probably cause a compiler error. The bool is not bitwise but the operation occurs outside the bool.

It's not comfortable code to look at.

@AmpBenzScientist it's not really adding a 1 because that's an AND, not an OR. and in C/C++, bool is just an integer type. it's considered true if nonzero.

@AmpBenzScientist in Java/C# it would probably cause a syntax error, but you typically don't see much bitmasking code of this sort in those languages. i could have mentioned that this is C99 code (earlier revisions lack a "bool" type) i guess.

@AmpBenzScientist the code snippet would compile and run just fine in C if that was an int and not a bool, but i wanted to give some hints as to what you're supposed to do with the result (seeing as it's a truth value).

@lore Embarrassingly enough I seem to have mostly used something closer to ANSI C or C89. I do recall conditionals being used extensively. Well I guess I'll have to check out Fatboy Slim You've come a long way, Baby.
*/
There's also this dead give away from my code.
/*

@lore That's likely where I got confused. In Mathematics the tilde (~) is used to negate. For a Boolean value we used T or F instead of 0 and 1. This is because they are True or False and the 0 or 1 could imply that they are integers. While {0,1} are a subset of Integers, they are merely place holders and not subject to operations.

Perhaps what confused me the most was that there was no mod 2 operation visible. I do assume at first that it would return two values but I couldn't understand why it would do so.
(See nearly every example of C with return 0 ie it worked or the other numbers from where code failed.)

The more I looked at it, it started to appear to be a weird Comp Sci thing and it did turn into more weird Comp Sci things. I've used C for a while and Cpp until around 4 years ago when Cpp++ really made me hate it.

I'm stumped, it seemingly returns bit flipped X (or negation X) And 1. I don't see what it does and I'm not cheating and compiling it. Assuming that X has the value of 0 it could bit flip to 1 and that's what the result is but I really don't get what the & 1 is doing. Very humbling.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.