true/false=1/0 not explained
-
Documentation clarification: Using Controls', it's explained that controls(0).a returns true or false. In fact, the function returns 0 or 1 (if you print the value). At this step, we haven't explained that 0 is false and 1 is true. I may be wrong on this but I haven't found an explanation earlier.
-
that's true (hehehe) in most languages. In some, I think C too, a boolean type takes a whole byte of memory so all the bits are dedicated to it. If a boolean is true, then all bits are high, the opposite is true if it's false. Using an integer value to represent this also works; just make it 0 or >0. However, signed integers can also be used to return negative values which are less than zero. This is often used to tell if an error occurred. But why use boolean types anyways? I think the best reasons to do so involve making the code somewhat more readable when there's no need for error handling
-
@turtleStew said in true/false=1/0 not explained:
that's true (hehehe) in most languages. In some, I think C too, a boolean type takes a whole byte of memory so all the bits are dedicated to it. If a boolean is true, then all bits are high, the opposite is true if it's false. Using an integer value to represent this also works; just make it 0 or >0. However, signed integers can also be used to return negative values which are less than zero. This is often used to tell if an error occurred. But why use boolean types anyways? I think the best reasons to do so involve making the code somewhat more readable when there's no need for error handling
that's how it works in c, flase is only produced by 0, all the other values are considered true, even with signed values, but some other languages implements boolean types using enumarative types or custom classes, that's to give more restrictive and specifiec usages to boolean types, or just to optimize the compilers for the usage of those values