Bit numbering
{{short description|Convention to identify bit positions}}
In computing, bit numbering is the convention used to identify the bit positions in a binary number.
Bit significance and indexing<span class="anchor" id="Most significant bit"></span><span class="anchor" id="Least significant bit"></span>
class="wikitable float-right" border="1" style="text-align:right; font-size: xx-small;" | ||||||||
style="width:7.7em; text-align:center;"| 150dec | style="width:2.4em; background:#D9DBFF; border-right: hidden;" | MSb | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em;background:#FFFFB0;"| LSb |
| Bit Content | style="text-align:center; background:#D9DBFF;"|1 | style="text-align:center;"|0 | style="text-align:center;"|0 | style="text-align:center;"|1 | style="text-align:center;"|0 | style="text-align:center;"|1 | style="text-align:center;"|1 | style="text-align:center;background:#FFFFB0"|0 |
{{anchor|Most significant byte}}{{anchor|Least significant byte}}
In computing, the least significant bit (LSb) is the bit position in a binary integer representing the lowest-order place of the integer. Similarly, the most significant bit (MSb) represents the highest-order place of the binary integer. The LSb is sometimes referred to as the low-order bit. Due to the convention in positional notation of writing less significant digits further to the right, the LSb also might be referred to as the right-most bit. The MSb is similarly referred to as the high-order bit or left-most bit. In both cases, the LSb and MSb correlate directly to the least significant digit and most significant digit of a decimal integer.
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.
A diagram showing how manipulating the least significant bits of a color can have a very subtle and generally unnoticeable effect on the color. In this diagram, green is represented by its RGB value, both in decimal and in binary. The red box surrounding the last two bits illustrates the least significant bits changed in the binary representation.
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.
class="wikitable float-right" border="1" style="text-align:right; font-size: xx-small;" | ||||||||
style="width:7.7em; text-align:center;"| 149dec in LSb0 | style="width:2.4em; border-right: hidden;" | MSb | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em;"| LSb |
| Bit Weight | style="background:#FFFFB0"| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Bit Content | style="text-align:center;"|1 | style="text-align:center;"|0 | style="text-align:center;"|0 | style="text-align:center;"|1 | style="text-align:center;"|0 | style="text-align:center;"|1 | style="text-align:center;"|0 | style="text-align:center"|1 |
Signed integer example
This table illustrates an example of an 8 bit signed decimal value using the two's complement method. The MSb most significant bit has a negative weight in signed integers, in this case −27 = −128. The other bits have positive weights. The lsb (least significant bit) has weight 1. The signed value is in this case −128+2 = −126.
class="wikitable float-right" border="1" style="text-align:right; font-size: xx-small;" | ||||||||
style="width:7.7em; text-align:center;"| -126dec in LSb0 | style="width:2.4em; border-right: hidden;" | MSb | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em;"| LSb |
| Bit Weight | style="background:#FFFFB0"| −128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Bit Content | style="text-align:center;"|1 | style="text-align:center;"|0 | style="text-align:center;"|0 | style="text-align:center;"|0 | style="text-align:center;"|0 | style="text-align:center;"|0 | style="text-align:center;"|1 | style="text-align:center"|0 |
Most- vs least-significant bit first<span class="anchor" id="Order"></span>
The expressions most significant bit first and least significant bit at first are indications on the ordering of the sequence of the bits in the bytes sent over a wire in a serial transmission protocol or in a stream (e.g. an audio stream).
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 least significant bit will arrive first: hence e.g. the same hexadecimal number 0x12
, again 00010010
in binary representation, will arrive as the (reversed) sequence 0 1 0 0 1 0 0 0
.
LSb 0 bit numbering<span class="anchor" id="LSB 0"></span>
class="wikitable float-right" border="1" style="text-align:right; font-size: xx-small;" | ||||||||
style="width:7.7em; text-align:center;"| 150dec in LSb0 | style="width:2.4em; background:#D9DBFF; border-right: hidden;" | MSb | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em;background:#FFFFB0;"| LSb |
| Bit Number | style="border-right: hidden;" |7 | style="border-right: hidden;" | | style="border-right: hidden;" | | style="border-right: hidden;" | | style="border-right: hidden;" | | style="border-right: hidden;" | | style="border-right: hidden;" | | style="background:#FFFFB0;"| 0 |
| Bit Weight | 128 | 64 | 32 | 16 | 8 | 4 | 2 | style="background:#FFFFB0"| 1 |
| Bit Content | style="text-align:center;"|1 | style="text-align:center;"|0 | style="text-align:center;"|0 | style="text-align:center;"|1 | style="text-align:center;"|0 | style="text-align:center;"|1 | style="text-align:center;"|1 | style="text-align:center;background:#FFFFB0"|0 |
When the bit numbering starts at zero for the least significant bit (LSb) the numbering scheme is called LSb 0.{{cite book
| author = Langdon, Glen G.
| title = Computer Design
| publisher = Computeach Press Inc
| year = 1982
| isbn = 0-9607864-0-6
| page = [https://archive.org/details/computerdesign00lang/page/52 52]
| url-access = registration
| url = https://archive.org/details/computerdesign00lang/page/52
}} This bit numbering method has the advantage that for any unsigned number the value of the number can be calculated by using exponentiation with the bit number and a base of 2.{{cite web |url=http://www.xcprod.com/titan/XCSB-DOC/bit_numbers.html |title=Bit Numbers |access-date=2021-03-30}} The value of an unsigned binary integer is therefore
:
where bi denotes the value of the bit with number i, and N denotes the number of bits in total.
MSb 0 bit numbering<span class="anchor" id="MSB 0"></span>
class="wikitable float-right" border="1" style="text-align:right; font-size: xx-small;" | ||||||||
style="width:7.7em; text-align:center;"| 150dev in MSb0 | style="width:2.4em; background:#D9DBFF; border-right: hidden;" | MSb | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em; border-right: hidden;" | | style="width:2.4em;background:#FFFFB0;"| LSb |
| Bit Number | style="background:#D9DBFF; border-right: hidden;" |0 | style="border-right: hidden;" | | style="border-right: hidden;" | | style="border-right: hidden;" | | style="border-right: hidden;" | | style="border-right: hidden;" | | style="border-right: hidden;" | | 7 |
| Bit Weight | style="background:#D9DBFF"| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Bit Content | style="text-align:center;background:#D9DBFF;"|1 | style="text-align:center;"|0 | style="text-align:center;"|0 | style="text-align:center;"|1 | style="text-align:center;"|0 | style="text-align:center;"|1 | style="text-align:center;"|1 | style="text-align:center;"|0 |
When the bit numbering starts at zero for the most significant bit (MSb) the numbering scheme is called MSb 0.
The value of an unsigned binary integer is therefore
:
LSb calculation
LSb of a number can be calculated with time complexity of with formula a & (~ a+1)
, where &
means binary AND and ~
means binary NOT.