MOST SIGNIFICANT BIT
In computing, the 'most significant bit' ('msb') is the bit position in a binary number having the greatest value. The msb is sometimes referred to as the 'left-most bit', due to the convention in positional notation of writing more significant digits further to the left.
The msb can also correspond to the sign of the binary number in one or two's complement notation. "1" meaning negative and "0" meaning positive.
'MSB', in all capitals, can also stand for "'most significant ''byte'''". The meaning is parallel to the above: it is the byte in that position of a multi-byte number which has the greatest potential value.
By extension, the 'most significant bits' (plural) are the bits of the number closest to, and including, the msb.
The binary representation of decimal 149, with the msb highlighted. The msb in an 8-bit binary number represents a value of 128 decimal. The lsb represents a value of 1.
| Contents |
| Conventions |
| Computing position of most significant 1 bit of an integer |
| References |
| See also |
Conventions
In referencing specific bits within a binary number, it is common to assign each bit a bit number, ranging from zero upwards to one less than the number of bits in the number. However, the order used for this assignment may be in either direction, and both orderings are used (in different contexts). This is one reason why "msb" is often used to designate the high-order bit instead of a bit number (which has greater potential for confusion).
Computing position of most significant 1 bit of an integer
The following code example for the C language is an algorithm to compute the position of most significant 1 bit of a 32 bit integer. [1] Operator '>>' represents 'unsigned right shift'.
/
★
★
★ Returns the most significant bit position of n from 0 to 31.
★ -1 is returned if n is 0.
★ /
int mostSignificantBitPosition(unsigned int n) {
int pos = 0;
int tmp;
tmp = n >> 16;
if (tmp != 0) { n = tmp; pos = pos + 16; }
tmp = n >> 8;
if (tmp != 0) { n = tmp; pos = pos + 8; }
tmp = n >> 4;
if (tmp != 0) { n = tmp; pos = pos + 4; }
tmp = n >> 2;
if (tmp != 0) { n = tmp; pos = pos + 2; }
tmp = n >> 1;
if (tmp != 0) { n = tmp; pos = pos + 1; }
return pos + n - 1;
}
References
1.
See also
★ Least significant bit
★ Binary numeral system
★ Signed number representations
★ Two's complement
★ Bit numbering
This article provided by Wikipedia. To edit the contents of this article, click here for original source.
psst.. try this: add to faves

العربية
中国
Français
Deutsch
Ελληνική
हिन्दी
Italiano
日本語
Português
Русский
Español