View Single Post
Old 28 October 2019, 18:48   #12
Registered User

Daedalus's Avatar
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 4,385
Yeah, the names can be a little confusing. Boolean is a *type* of logic, where you can only have two values, true or false, 1 or 0. A boolean variable is one which is essentially 1 bit. In computing terms, "logical" is usually used to describe operations where each entire term is taken as boolean, so each value can be either true or false, regardless of what arrangement of bits they actually contain. "Bitwise" is used to refer to operations that focus on the individual bits of a value, rather than what it represents overall. C has explicit operators that differentiate the two, ! is (boolean) logical NOT and ~ is bitwise NOT. Blitz doesn't really have that same concept of boolean values, and so internally represents true as -1 and false as 0. So something like
NPrint 5>3
will produce -1 as the output, because 5 is greater than 3. The reason it does this is that -1 (true) is represented in binary as all ones (%11111111), and 0 (false) is represented as all zeroes (%00000000). Thus, doing a bitwise NOT (flipping every bit in the value) swaps true to false and false to true. So
NPrint NOT 5>3
will output 0.
This works for all Blitz operations that are boolean in nature, however it does mean that Blitz can't check for a zero value by doing e.g. NOT filehandle as is common in C (!filehandle). Instead, filehandle <> 0 is used.
Daedalus is offline  
Page generated in 0.04787 seconds with 11 queries