Truth bit
Encyclopedia
A truth bit or truth flag in computer science
Computer science
Computer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...

 is an indicator that needs to be only one bit long (within any byte
Byte
The byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...

) whose value is either 1 or 0 - representing TRUE or FALSE. Sometimes a whole byte
Byte
The byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...

 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
Byte
The byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...

 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 statement
Conditional statement
In computer science, conditional statements, conditional expressions and conditional constructs are features of a programming language which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false...

s (eg 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 table
Decision table
Decision tables are a precise yet compact way to model complicated logic.Decision tables, like flowcharts and if-then-else and switch-case statements, associate conditions with actions to perform, but in many cases do so in a more elegant way....

s to be implemented by mapping to their binary representations in memory.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK