Boolean Data type
A Boolean variable is stored in a 16-bit (2-byte) numeric form, but only True or False. The value of a Boolean variable is displayed as True or False (when using Print), or #TRUE # or #FALSE # (when using Write #). Use the keyword True and False to assign a boolean variable to one of these two states.
When you convert a boolean value of another numeric type, 0 turns to False, and the other value becomes True. When you convert a Boolean value to another data type, False becomes 0, and True becomes-1.
Standard C does not have a Boolean type , and it replaces the Boolean type with an integral type, which is 0/1.
Boolean type is not supported in the C language standard before ISO99-a comparison operator results in an integral type, and the result of the test expression does not have a type check. C99 adds Boolean types (_bool and Bool,true and false macros are defined in stdbool.h), but does not enforce type checking. Splint supports Boolean type checking. Many common errors can be detected by introducing independent Boolean types and strong type checks.
the Boolean in VB
A Boolean data type is a special case of an integer data type . A Boolean data type can contain true or false;microsoft®visual basic®for applications (VBA) stores a value of true to-1, and the value of False Stored as 0.
You can use the CBool function to convert any numeric value to a boolean value. When you convert another numeric data type to a boolean value, any non 0 values are equivalent to True, and the 0 value (0) is equivalent to False. For example, Bool (7) returns True, and CBool (5 + 2–7) returns False because it is CBool (0) after calculation.
The following procedure determines whether a number is even. This procedure uses the MOD operator to determine whether a number is more than 2 after dividing it. If the number is even, then there is no remainder after dividing by 2, and if the number is odd, then the remainder is 1 after dividing by 2.
Boolean
' Determines whether a number is even or odd.
If lngnum Mod 2 = 0 Then
IsEven = True
Else
IsEven = False end
If end
Function
Another way to write this procedure is to convert the result of an expression to a Boolean value, and then switch its value using the NOT keyword, as shown in the following example. If the lngnum argument is odd, it must be a value other than 0; converting the lngnum to a boolean value will output True. This procedure must return False because the value is odd, so switching the Boolean value using the NOT keyword will produce the correct result.
Boolean
' Determines whether a number is even or odd.
IsEven = Not CBool (lngnum Mod 2)
End Function
Note that the revised IsEven process compresses the If hen statement of five lines into a single line of code. If you use the If Hen statement to set a value to True under a certain condition and set the value to False under another condition, as the IsEven procedure does, you can compress the IF Chamber hen statement by modifying the conditions that return true or False. However, the revised process may be more difficult to understand.