Boolean flag


A boolean flag, truth bit or truth flag in computer science is a Boolean value represented as one bit

Memory usage

A single byte can contain up to 8 separate Boolean flags, making it a very economical method of storage.

Efficiency

Most computer languages support the setting and testing of single or multiple bits in combination for use as truth indicators and usually up to 256 different combinations of conditions can be tested for with just a single instruction on one byte.

Usage

Sometimes, programs are written to simply set flags when certain conditions are detected, rather than have multiple nested conditional statements that can get quite complex. When all the conditions are tested for and all flags set on or off appropriately, testing can commence on various combinations of conditions - by reference to the flags instead of the variables themselves. This can simplify processing considerably and allows decision tables to be implemented by mapping to their binary representations in memory.