>he uses mod 2 instead of bitwise and 1 to test for odd/even numbers
>>59822436
what's the difference though?
>>59822754
OP gets to be a special snowflake by using the second method.
>>59822754
None. The compiler does the same either way. Mod 2 is more readable / easier to understand.
>>59822781
Kill yourself, you dumb fucking shit stain.
>>59822787
Niceme.me
>>59822784
Yes, it is easier to read and understand (for script kiddies that don't know what a bit is)
>>59822754
Bit test is what the compiler turns modulus 2 in to. All it does is prove you don't know what bitwise and does.
>>59822885
>All it does is prove you don't know what bitwise and does.
Yeah that'll surely keep me up at night.
>>59822436
My processor reads java bytecode and has no idea what a bitwise is.
>>59822894
> Interviewee 1 does % 2
> Interviewee 2 does & 1
Outcomes
> Interviewer is a dumbshit and thinks & 1 will confuse people.
> Interviewer actually knows that to check if base 2 number odd you see if the first bit is 1.
>>59822972
Interviewer knows interviewee is correct, but solving it that way is a measure of immense autism. Interviewer decides he is not a good "cultural fit"
>>59822972
>Outcomes
>Interviewer doesn't give a shit because they both work and bitwise operations weren't a requirement of the test.
>>59822972
>Interviewer picks the interviewee who doesn't have autism because working with a team is essential
>you don't get the job
Obviously the correct way isbool iseven (int x)
{
if (x & 0 == 0)
return false;
else
return true;
}
>>59823133
>working with a team is essential
If your team doesn't know about bitwise operations, then it sucks. mod 2 has no advantage over &1.
>>59825838
Yes it does dumb ass, it's readable and intuitive, you're acting like bitwise operators are some sacred thing only you know of lmao, literally like csc 102.
>>59825761
>not doing return !(x & 0 == 0);
>>59825761bool iseven (int x)
{
int i = x/2;
if (x - i*2 != 0)
return false;
else
return true;
}
ftfy
>>59822436
Doing that ties your code to a specific endianess aka a less portable solution.
>>59822784
>>59822885
Last I checked the JVM wouldn't do that
Won't your compiler just optimise that anyway?