Bit numbering
In
Bit significance and indexing
In
Bit indexing correlates to the positional notation of the value in base 2. For this reason, bit index is not affected by how the value is stored on the device, such as the value's byte order. Rather, it is a property of the numeric value in binary itself. This is often utilized in programming via bit shifting: A value of 1 << n
corresponds to the nth bit of a binary integer (with a value of 2n
).
Least significant bit in digital steganography
In digital steganography, sensitive messages may be concealed by manipulating and storing information in the least significant bits of an image or a sound file. The user may later recover this information by extracting the least significant bits of the manipulated pixels to recover the original message. This allows the storage or transfer of digital information to remain concealed.
Unsigned integer example
This table illustrates an example of decimal value of 149 and the location of LSb. In this particular example, the position of unit value (decimal 1 or 0) is located in bit position 0 (n = 0). MSb stands for most significant bit, while LSb stands for least significant bit.
Binary (Decimal: 149) | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 1 |
---|---|---|---|---|---|---|---|---|
Bit weight for given bit position n ( 2n ) | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
Bit position label | MSb | LSb |
Most- vs least-significant bit first
The expressions most significant bit first and least significant bit at last are indications on the ordering of the sequence of the bits in the bytes sent over a wire in a
Most significant bit first means that the most significant bit will arrive first: hence e.g. the hexadecimal number 0x12
, 00010010
in binary representation, will arrive as the sequence 0 0 0 1 0 0 1 0
.
Least significant bit first means that the
0x12
, again 00010010
in binary representation, will arrive as the (reversed) sequence 0 1 0 0 1 0 0 0
.
LSb 0 bit numbering
When the bit numbering starts at zero for the
where bi denotes the value of the bit with number i, and N denotes the number of bits in total.
MSb 0 bit numbering
When the bit numbering starts at zero for the
The value of an unsigned binary integer is therefore
Other
ALGOL 68's elem operator is effectively "MSb 1 bit numbering" as the bits are numbered from left to right, with the first bit (bits elem 1) being the "most significant bit", and the expression (bits elem bits width) giving the "least significant bit". Similarly, when bits are coerced (typecast) to an array of Boolean ([ ]bool bits), the first element of this array (bits[lwb bits]) is again the "most significant bit".
For MSb 1 numbering, the value of an unsigned binary integer is
PL/I numbers BIT strings starting with 1 for the leftmost bit.
The Fortran BTEST function uses LSb 0 numbering.
See also
- ARINC 429
- Binary numeral system
- Signed number representations
- Two's complement
- Endianness
- Binary logarithm
- Unit in the last place (ULP)
- Find first set
- MAC address: Bit-reversed notation
References
- ISBN 0-9607864-0-6.
- ^ "Bit Numbers". Retrieved 2021-03-30.