Bit numbering
In computing, bit numbering (or sometimes bit endianness) is the convention used to identify the bit positions in a binary number or a container for such a value. The bit number starts with zero and is incremented by one for each subsequent bit position.
Contents
LSB 0 bit numbering
When the bit numbering starts at zero for the least significant bit the numbering scheme is called "LSB 0".[1] 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. 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
Similarly, when the bit numbering starts at zero for the most significant bit the numbering scheme is called "MSB 0".
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 LSB0 numbering.
Usage
Little-endian CPUs usually employ "LSB 0" bit numbering, however both bit numbering conventions can be seen in big-endian machines. Some architectures like SPARC and Motorola 68000 use "LSB 0" bit numbering, while S/390, PowerPC and PA-RISC use "MSB 0".[2]
The recommended style for Request for Comments documents is "MSB 0" bit numbering.[3][4]
Bit numbering is usually transparent to the software, but some programming languages like Ada allow specifying the appropriate bit order for data type representation.[5]
See also
References
<templatestyles src="Reflist/styles.css" />
Cite error: Invalid <references>
tag; parameter "group" is allowed only.
<references />
, or <references group="..." />
External links
- Bit Numbers
- Bit numbering for different CPUs:
- Motorola 68000 ("Bit manipulation" and "Reversed Bit-Numbering" sections)
- IBM Cell Broadband Processors ("Byte ordering and bit numbering")
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.
- ↑ Lua error in package.lua at line 80: module 'strict' not found.