Truth bit

From Wikipedia, the free encyclopedia

A truth bit or truth flag in computer science is an indicator that needs to be only one bit long (within any byte) whose value is either 1 or 0 - representing TRUE or FALSE. Sometimes a whole byte or longer character variable is used for this purpose and may contain values such as

  • Y or N, or
  • YES or NO or
  • TRUE or FALSE

as an alternative to binary 0 or 1.

Memory usage

A single byte can contain up to 8 separate truth bits, making it a very economical method of storage in comparison with other methods.

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 (e.g. IF's) 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.

See also

This article is issued from Wikipedia. The text is available under the Creative Commons Attribution/Share Alike; additional terms may apply for the media files.