<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.formulasearchengine.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=93.29.102.125</id>
	<title>formulasearchengine - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.formulasearchengine.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=93.29.102.125"/>
	<link rel="alternate" type="text/html" href="https://en.formulasearchengine.com/wiki/Special:Contributions/93.29.102.125"/>
	<updated>2026-09-24T12:40:21Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.47.0-wmf.7</generator>
	<entry>
		<id>https://en.formulasearchengine.com/w/index.php?title=ROT_(aviation)&amp;diff=8026</id>
		<title>ROT (aviation)</title>
		<link rel="alternate" type="text/html" href="https://en.formulasearchengine.com/w/index.php?title=ROT_(aviation)&amp;diff=8026"/>
		<updated>2014-01-28T06:48:53Z</updated>

		<summary type="html">&lt;p&gt;93.29.102.125: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Unreferenced|date=December 2009}}&lt;br /&gt;
{{merge|Bit field|date=April 2013}}&lt;br /&gt;
&lt;br /&gt;
In [[computer programming]], a &#039;&#039;&#039;flag word&#039;&#039;&#039; can refer to one or more [[bit]]s that are used to store a [[binary numeral system|binary]] value or [[code]] that has an assigned meaning, but can refer to uses of other data types.  Flags are typically found as members of a defined [[data structure]], such as a [[Row (database)|database record]], and the meaning of the value contained in a flag will generally be defined in relation to the data structure it is part of.  In many cases, the binary value of a flag will be understood to represent one of several possible states or statuses.  In other cases, the binary values may represent one or more attributes in a [[bit field]], often related to abilities or permissions, such as &amp;quot;can be written to&amp;quot; or &amp;quot;can be deleted&amp;quot;.  However, there are many other possible meanings that can be assigned to flag values.  One common use of flags is to mark or designate data structures for future processing.&lt;br /&gt;
&lt;br /&gt;
Within [[microprocessor]]s and other logic devices, flags are commonly used to control or indicate the intermediate or final state or outcome of different operations.  Microprocessors typically have, for example, a [[status register]] that is composed of such flags, and the flags are used to indicate various post-operation conditions, such as when there has been an [[arithmetic overflow]].  The flags can be utilized in subsequent operations, such as in processing conditional [[Branch (computer science)|jump instruction]]s. For example a &#039;&#039;je&#039;&#039; (Jump if Equal) instruction in the [[X86 assembly language#Programming flow|X86 assembly language]] will result in a jump if the Z (zero) flag was set by some previous operation.&lt;br /&gt;
&lt;br /&gt;
A [[Command-line interface#Command-line option|command line switch]] is also known as a flag.  [[Command-line interface|Command line]] programs often start with an option [[Parsing|parser]] that translates command line switches into flags in the sense of this article.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
===Processor status register===&lt;br /&gt;
Taking the example of a [[MOS Technology 6502|6502]] processor&#039;s [[status register]], the following information was held within 8 bits:&lt;br /&gt;
&lt;br /&gt;
* Bit 7. Negative flag&lt;br /&gt;
* Bit 6. Overflow flag&lt;br /&gt;
* Bit 5. Unused&lt;br /&gt;
* Bit 4. Break flag&lt;br /&gt;
* Bit 3. Decimal flag&lt;br /&gt;
* Bit 2. Interrupt-disable flag&lt;br /&gt;
* Bit 1. Carry flag&lt;br /&gt;
* Bit 0. Zero flag &lt;br /&gt;
&lt;br /&gt;
As you can see, a lot of information about the state of the processor can be packed into 8 bits.&lt;br /&gt;
&lt;br /&gt;
===Unix process exit code===&lt;br /&gt;
A more general example would be the use of a [[Unix]] [[exit status]] as a flag word. In this case, the exit code is by the programmer to pass status information to another process. An imaginary program which returns the status of 8 burglar alarm switches connected to the printer port could set each of the bits in the exit code in turn, depending on whether the switches are closed or open.&lt;br /&gt;
&lt;br /&gt;
==Extracting bits from flag words==&lt;br /&gt;
&lt;br /&gt;
To read a status byte, assuming your programming language does not offer this facility by default, is quite easy. You simply need to [[Logical conjunction|AND]] the status byte with a [[Mask (computing)|mask byte]]. The mask byte should have only the bit corresponding to the flag you want to read set, as in the example below.&lt;br /&gt;
&lt;br /&gt;
Suppose that status byte 103 (decimal) is returned, and that we want to check flag bit 5.&lt;br /&gt;
&lt;br /&gt;
The flag we want to read is number 5 (counting from zero) - so the mask byte will be &amp;lt;math&amp;gt;2^5 = 32&amp;lt;/math&amp;gt;. ANDing 32 with 103 gives 32, which means the flag bit is set. If the flag bit was not set, the result would have been 0.&lt;br /&gt;
&lt;br /&gt;
In modern computing, the [[logical shift|shift]] operator (&amp;amp;lt;&amp;amp;lt;) can be used to quickly perform the power-of-two. In general, a mask with the Nth bit set can be computed as&lt;br /&gt;
 (1 &amp;lt;&amp;lt; n)&lt;br /&gt;
&lt;br /&gt;
Thus to check the Nth bit from a variable &#039;&#039;&#039;v&#039;&#039;&#039;, we can perform the operation&lt;br /&gt;
 bool nth_is_set = (&#039;&#039;&#039;v&#039;&#039;&#039; &amp;amp; (1 &amp;lt;&amp;lt; n)) != 0&lt;br /&gt;
&lt;br /&gt;
==Changing bits in flag words==&lt;br /&gt;
&lt;br /&gt;
Writing, reading or toggling bits in flags can be done only using the OR, AND and NOT operations - operations which can be performed quickly in the processor.&lt;br /&gt;
&lt;br /&gt;
To set a bit, [[Logical operator|OR]] the status byte with a mask byte. Any bits set in the mask byte or the status byte will be set in the result.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
 int setBit(int val, int bit_position)&lt;br /&gt;
 {&lt;br /&gt;
   return val | (1 &amp;lt;&amp;lt; bit_position);&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
To clear a bit, perform a [[Negation|NOT]] operation on the mask byte, then AND it with the status byte. The result will have the appropriate flag cleared (set to 0).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
 int clearBit(int val, int bit_position)&lt;br /&gt;
 {&lt;br /&gt;
   return val &amp;amp; ~(1 &amp;lt;&amp;lt; bit_position);&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
To toggle a bit, [[Exclusive disjunction|XOR]] the status byte and the mask byte. This will set a bit if it is cleared or clear a bit if it is set.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
 int toggleBit(int val, int bit_position)&lt;br /&gt;
 {&lt;br /&gt;
   return val ^ (1 &amp;lt;&amp;lt; bit_position);&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Bit field]]&lt;br /&gt;
*[[Bit array]]&lt;br /&gt;
*[[Status register]]&lt;br /&gt;
*[[FLAGS register (computing)]]&lt;br /&gt;
*[[Program status word]]&lt;br /&gt;
*[[Control register]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming idioms]]&lt;br /&gt;
[[Category:Operating system technology]]&lt;br /&gt;
[[Category:Central processing unit]]&lt;br /&gt;
[[Category:Digital registers]]&lt;/div&gt;</summary>
		<author><name>93.29.102.125</name></author>
	</entry>
</feed>