Flag word

With Flag [ flæg ] ( also German flag) is called a binary variable or a status indicator, which can be used as an aid for the identification of certain states. A flag can be set, cleared or read.

Flags in the processor

A flag featuring, for example, in arithmetic calculations to carry ( carry flag ) or the overflow ( overflow flag ), see also the status register.

Flags in programming

With the introduction of flags can also be carried out in the programming, for example, to convey the existence of an error condition in one segment to another segment or program to implement user rights.

Which format has the flag depends on the implementation: Both the typical binary values ​​0 and 1 as well as for humans understandable variants such as " Yes " and "No" can be seen as Flag. Here, flags in many programming languages ​​can be implemented on bitwise operators.

Flags that can assume more than two values ​​are not referred to as " flag", but as a status variable. From the English language can be found in the programming for synchronizing state variables, the term semaphore.

For example in C

Char flag = 0; / / a flag one takes usually the smallest possible data types   if ( flag ) puts (" The flag is on"); / / applies to C 0 as false; everything else is considered true (! flag ) if puts (" The flag is off"); / / Reversal of Fortune Heist value of flag                                      / / Output: The flag is made ​​of   flag = 1 - flag; / / Flip- flop: from 1 becomes 0 and 0 becomes 1   if ( flag ) puts (" The flag is on " ) else puts (" The flag is off");                                      / / Output: The flag is on   flag = ~ flag; / / Alternative to flip- flop: Bitwise not of 00000000 is 11111111 and vice versa                                      / / not compatible with the first alternative (~ 00000001 = 11111110, both are true) conceptual history

The English term flag is related to German flag, but should never be translated. In the English language is an extended term significance has emerged, in which not only show the flag to flag, set, means pull, but more generally signal and hail says ( to flag down a taxi, a taxi hail ). This is probably due to the custom in rural areas of the United States back in the letter box at the ( away from the house ) land access to install a small ( red ) flag that was pushed up when new mail is loaded (incoming or outgoing). Instead of the cumbersome concept of semaphores for such signaling devices spread the word flag - the flag of the form and name of semaphore as going back to the optical telegraph and semaphore alphabet.

  • Computer Architecture
  • Data type