The BOOLEAN function returns a result equal to Expression converted to boolean.

## Notes

• A boolean variable is actually a variable of type byte with a special boolean flag.
• The type code for boolean variables is 1 (the same as byte).
• You can use the ISA function with the BOOLEAN keyword to determine if a variable is a boolean.
• You can pass boolean variables into any IDL function that accepts byte data - the data will be treated as just an array of 0's or 1's.
• When you use a boolean variable in a math expression, the boolean flag is ignored and the result will not be a boolean. The only exception is the logical negation operator "~", which preserves the boolean flag.
• When changing elements within a boolean array, the values will be converted to either true (1) or false (0). See the rules under Return Value below.
• HELP will print out the data type as BOOLEAN, even though the actual type is byte.
• Implied print will print out the words "true" or "false" for boolean values. Normal print will print out the values 1 or 0.
• If you save a boolean variable in an IDL SAVE file, and then restore that file in IDL 8.3 or earlier, the boolean flag will be quietly ignored and the variable will be restored as a simple byte variable.

## Example

`a = [0.0, 1.0, 0.0, 3.0]`
`b = BOOLEAN(a)`
`b = "yes" ; equal to "true"`
`HELP, b`
`PRINT, b`
`PRINT, JSON_SERIALIZE(b)`

IDL prints:

`B  BOOLEAN   = Array`
`0  1  1  1`
`[false,true,true,true]`

## Syntax

Result = BOOLEAN( Expression )

## Return Value

Returns a boolean value or array of the same dimensions as the Expression. The following rules are used for conversion:

• For numeric data, all non-zero values become true (1). Zero values become false (0).
• For strings, all non-empty strings become true (1). Empty (null) strings become false (0).
• For pointers or objects, all valid heap variables become true (1). Null pointers or objects become false (0).

## Arguments

### Expression

The expression to be converted to boolean. Expression can be any data type except structure.