Boolean flag: Difference between revisions
Add content |
→Efficiency: Add citation |
||
Line 9: | Line 9: | ||
A single [[byte]] can contain up to 8 separate Boolean flags, making it a very economical and dense method of data storage. This is known as a packed representation or bit-packing, and the opposite encoding with only one bit per byte used is known as a sparse representation. |
A single [[byte]] can contain up to 8 separate Boolean flags, making it a very economical and dense method of data storage. This is known as a packed representation or bit-packing, and the opposite encoding with only one bit per byte used is known as a sparse representation. |
||
==Efficiency== |
==Efficiency== |
||
Most [[computer language|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 using [[Bitwise operation|bitwise operations]]. Advancements in [[processor design]] and [[parallel computing]] mean even more [[Boolean algebra]] operations on Boolean flags can be done with just a single instruction using [[SIMD]] technology, often implemented in programming languages as [[Intrinsic function|compiler intrinsic functions]]. |
Most [[computer language|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 using [[Bitwise operation|bitwise operations]]. Advancements in [[processor design]] and [[parallel computing]] mean even more [[Boolean algebra]] operations on Boolean flags can be done with just a single instruction using [[SIMD]] technology, often implemented in programming languages as [[Intrinsic function|compiler intrinsic functions]].<ref>{{cite web | title=Intel Intrinsics Guide | website=Intel Developer Zone | url=https://software.intel.com/sites/landingpage/IntrinsicsGuide/ | access-date=2021-04-10}}</ref> |
||
==Usage== |
==Usage== |
||
Sometimes, programs are written to simply set flags when certain conditions are detected, rather than have multiple nested [[Conditional (programming)|conditional statement]]s (e.g. <code>if</code>s) that can get quite complex. When all the conditions are tested for and all flags set on or off appropriately, [[Software testing|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]]s to be implemented by mapping to their binary representations in memory. |
Sometimes, programs are written to simply set flags when certain conditions are detected, rather than have multiple nested [[Conditional (programming)|conditional statement]]s (e.g. <code>if</code>s) that can get quite complex. When all the conditions are tested for and all flags set on or off appropriately, [[Software testing|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]]s to be implemented by mapping to their binary representations in memory. |
Revision as of 12:22, 10 April 2021
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages)
|
A Boolean flag, truth bit or truth flag in computer science is a Boolean value represented as one bit, which encodes a state variable with two possible values.
Memory usage
A single byte can contain up to 8 separate Boolean flags, making it a very economical and dense method of data storage. This is known as a packed representation or bit-packing, and the opposite encoding with only one bit per byte used is known as a sparse representation.
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 using bitwise operations. Advancements in processor design and parallel computing mean even more Boolean algebra operations on Boolean flags can be done with just a single instruction using SIMD technology, often implemented in programming languages as compiler intrinsic functions.[1]
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
References
- ^ "Intel Intrinsics Guide". Intel Developer Zone. Retrieved 2021-04-10.