It just plain makes more sense to have every other value, including negative ones be true besides 0. 0 is the only number where every bit is set to 0, every other value has at least one bit set to 1. This is even reflected in Assembly where you have the jnz (jump if not zero) and the jz (jump if zero) instruction.
Not exactly. The language looks like Java to me. At least in Java 8, 1 is not equivalent to true and 0 is not false. Even in the tutorials I see geeksforgeeks, they are using an if - else statement for the conversion. Edit: Just realised this is C#. Anyway, same issue here so. Implicit conversion from int to bool is not allowed.
It's C#, and apparently they are using the unity engine which stores bools as 0 or 1 integers, which is why this works. They are only converting that 0 or 1 to false or true, in theory it should never be a 2 or 3, if it is, something is messing up elsewhere.
Doesn't excuse the fact it's still badcode tho lol.
Not really, booleans are typically stored as a byte, and it's value can range from 0 - 255. 0 is false, and everything else is normally true. In this instance, everything but 1 is false.
What environment normally stores integers as a byte? Yes, it is never a “bit” as that isn’t addressable. More typically the machine’s word size, 32 bit, or the min(32, word size)…
View all comments
Show parent comment
32
u/[deleted] Feb 02 '22
Funny thing is: it works.