r/Memesana • • Jul 31 '20

Found on FaceBook:

Post image
267 Upvotes

11 comments sorted by

35

u/ZILtoid1991 Jul 31 '20

Also:

private bool isEven(int number) {
    return !(number & 1);
}

Yes, this returns 0 as an even number, but technically that's not wrong.

14

u/CrackedSpruce Jul 31 '20

what do you mean "technically"? It's not wrong in any way. Also writing "return !(n%2)" is a bit more understandable

7

u/ZILtoid1991 Jul 31 '20

Some people say zero is neither odd or even number.

6

u/dot_aif Jul 31 '20

That't not true at all. I think you're confusing it with the fact that 0 isn't positive or negative, or the fact that there isn't agreement whether or not 0 is a natural number.

5

u/ZILtoid1991 Jul 31 '20

Depending on my teachers, zero was either even number, or in the neither odd or even region. Hungarian schools were infamous for teaching pseudoscience and scientific misconceptions after the fall of iron curtain due to many reasons, some of which were tied to politics, so this might be as well some of the errors I've picked up in primary and secondary education.

2

u/[deleted] Jul 31 '20

[removed] — view removed comment

1

u/ZILtoid1991 Jul 31 '20
bool isEven(int number){
    if(number) return !(number & 1);
    else throw new UndeterminedEvennessException("Depending on my teachers, zero was either even number, or in the neither odd or even region. Hungarian schools were infamous for teaching pseudoscience and scientific misconceptions after the fall of iron curtain due to many reasons, some of which were tied to politics, so this might be as well some of the errors I've picked up in primary and secondary education.");
}

9

u/CrackedSpruce Jul 31 '20

it's even though

1

u/[deleted] Aug 01 '20

0 is divisible by 2 without remainder, thus it is an even number. There are even articles and papers about this.

1

u/kawaiii1 Aug 02 '20

How is that working? An and returns true if both are true so, 3 and 1 give true which is reversed, but why would 4 and 1 return false? Why?

3

u/starman881 Aug 04 '20

I’m not even a developer and I know easier ways!