Bit numbering

Last updated

In computing, bit numbering is the convention used to identify the bit positions in a binary number.

Contents

Bit significance and indexing

The binary representation of decimal 149, with the LSb highlighted. The LSb represents a value of 1. Least significant bit.svg
The binary representation of decimal 149, with the LSb highlighted. The LSb represents a value of 1.
The unsigned binary representation of decimal 149, with the MSb highlighted. The MSb represents a value of 128. Most significant bit.svg
The unsigned binary representation of decimal 149, with the MSb highlighted. The MSb represents a value of 128.

In computing, the least significant bit (LSb) is the bit position in a binary integer representing the binary 1s 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 or right-most bit, due to the convention in positional notation of writing less significant digits further to the right. 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

A diagram showing how manipulating the least significant bits of a color can have a very subtle and generally unnoticeable affect 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. LeastSignificantBitDemonstration.jpg
A diagram showing how manipulating the least significant bits of a color can have a very subtle and generally unnoticeable affect 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.

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)10010101
Bit weight for given bit position n ( 2n )2726252423222120
Bit position labelMSbLSb

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 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

LSb 0: A container for 8-bit binary number with the highlighted least significant bit assigned the bit number 0 Lsb0.svg
LSb 0: A container for 8-bit binary number with the highlighted least significant bit assigned the bit number 0

When the bit numbering starts at zero for the least significant bit (LSb) 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. [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

MSb 0: A container for 8-bit binary number with the highlighted most significant bit assigned the bit number 0 Msb0.svg
MSb 0: A container for 8-bit binary number with the highlighted most significant bit assigned the bit number 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

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

Related Research Articles

<span class="mw-page-title-main">Decimal</span> Number in base-10 numeral system

The decimal numeral system is the standard system for denoting integer and non-integer numbers. It is the extension to non-integer numbers of the Hindu–Arabic numeral system. The way of denoting numbers in the decimal system is often referred to as decimal notation.

<span class="mw-page-title-main">Floating-point arithmetic</span> Computer approximation for real numbers

In computing, floating-point arithmetic (FP) is arithmetic that represents subsets of real numbers using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. Numbers of this form are called floating-point numbers. For example, 12.345 is a floating-point number in base ten with five digits of precision:

In computer science, an integer is a datum of integral data type, a data type that represents some range of mathematical integers. Integral data types may be of different sizes and may or may not be allowed to contain negative values. Integers are commonly represented in a computer as a group of binary digits (bits). The size of the grouping varies so the set of integer sizes available varies between different types of computers. Computer hardware nearly always provides a way to represent a processor register or memory address as an integer.

<span class="mw-page-title-main">Numeral system</span> Notation for expressing numbers

A numeral system is a writing system for expressing numbers; that is, a mathematical notation for representing numbers of a given set, using digits or other symbols in a consistent manner.

The octal, or oct for short, is the base-8 positional numeral system, and uses the digits 0 to 7. This is to say that 10octal represents eight and 100octal represents sixty-four. However, English, like most languages, uses a base-10 number system, hence a true octal system might use different vocabulary.

A computer number format is the internal representation of numeric values in digital device hardware and software, such as in programmable computers and calculators. Numerical values are stored as groupings of bits, such as bytes and words. The encoding between numerical values and bit patterns is chosen for convenience of the operation of the computer; the encoding used by the computer's instruction set generally requires conversion for external use, such as for printing and display. Different types of processors may have different internal representations of numerical values and different conventions are used for integer and real numbers. Most calculations are carried out with number formats that fit into a processor register, but some software systems allow representation of arbitrarily large numbers using multiple words of memory.

Double-precision floating-point format is a floating-point number format, usually occupying 64 bits in computer memory; it represents a wide dynamic range of numeric values by using a floating radix point.

A binary number is a number expressed in the base-2 numeral system or binary numeral system, a method of mathematical expression which uses only two symbols: typically "0" (zero) and "1" (one).

A numerical digit is a single symbol used alone or in combinations, to represent numbers in a positional numeral system. The name "digit" comes from the fact that the ten digits of the hands correspond to the ten symbols of the common base 10 numeral system, i.e. the decimal digits.

Two's complement is the most common method of representing signed integers on computers, and more generally, fixed point binary values. Two's complement uses the binary digit with the greatest place value as the sign to indicate whether the binary number is positive or negative. When the most significant bit is 1, the number is signed as negative; and when the most significant bit is 0 the number is signed as positive.

Balanced ternary is a ternary numeral system that uses a balanced signed-digit representation of the integers in which the digits have the values −1, 0, and 1. This stands in contrast to the standard (unbalanced) ternary system, in which digits have values 0, 1 and 2. The balanced ternary system can represent all integers without using a separate minus sign; the value of the leading non-zero digit of a number has the sign of the number itself. The balanced ternary system is an example of a non-standard positional numeral system. It was used in some early computers and also in some solutions of balance puzzles.

<span class="mw-page-title-main">Power of two</span> Two raised to an integer power

A power of two is a number of the form 2n where n is an integer, that is, the result of exponentiation with number two as the base and integer n as the exponent.

<span class="mw-page-title-main">Positional notation</span> Method for representing or encoding numbers

Positional notation usually denotes the extension to any base of the Hindu–Arabic numeral system. More generally, a positional system is a numeral system in which the contribution of a digit to the value of a number is the value of the digit multiplied by a factor determined by the position of the digit. In early numeral systems, such as Roman numerals, a digit has only one value: I means one, X means ten and C a hundred. In modern positional systems, such as the decimal system, the position of the digit means that its value must be multiplied by some value: in 555, the three identical symbols represent five hundreds, five tens, and five units, respectively, due to their different positions in the digit string.

An organizationally unique identifier (OUI) is a 24-bit number that uniquely identifies a vendor, manufacturer, or other organization.

Non-standard positional numeral systems here designates numeral systems that may loosely be described as positional systems, but that do not entirely comply with the following description of standard positional systems:

A negative base may be used to construct a non-standard positional numeral system. Like other place-value systems, each position holds multiples of the appropriate power of the system's base; but that base is negative—that is to say, the base b is equal to −r for some natural number r.

Single-precision floating-point format is a computer number format, usually occupying 32 bits in computer memory; it represents a wide dynamic range of numeric values by using a floating radix point.

In computing, decimal32 is a decimal floating-point computer numbering format that occupies 4 bytes (32 bits) in computer memory. It is intended for applications where it is necessary to emulate decimal rounding exactly, such as financial and tax computations. Like the binary16 format, it is intended for memory saving storage.

LEB128 or Little Endian Base 128 is a variable-length code compression used to store arbitrarily large integers in a small number of bytes. LEB128 is used in the DWARF debug file format and the WebAssembly binary encoding for all integer literals.

The skew binary number system is a non-standard positional numeral system in which the nth digit contributes a value of times the digit instead of times as they do in binary. Each digit has a value of 0, 1, or 2. A number can have many skew binary representations. For example, a decimal number 15 can be written as 1000, 201 and 122. Each number can be written uniquely in skew binary canonical form where there is only at most one instance of the digit 2, which must be the least significant nonzero digit. In this case 15 is written canonically as 1000.

References

  1. Langdon, Glen G. (1982). Computer Design . Computeach Press Inc. p.  52. ISBN   0-9607864-0-6.
  2. "Bit Numbers" . Retrieved 2021-03-30.