In computing, a nibble[1] (occasionally nybble, nyble, or nybl to match the spelling of byte) is a four-bit aggregation,[1][2][3] or half an octet. It is also known as half-byte[4] or tetrade.[5][6] In a networking or telecommunication context, the nibble is often called a semi-octet,[7] quadbit,[8] or quartet.[9][10] A nibble has sixteen (24) possible values. A nibble can be represented by a single hexadecimal digit (0F) and called a hex digit.[11]

An octet code page 866 font table ordered by nibbles.

A full byte (octet) is represented by two hexadecimal digits (00FF); therefore, it is common to display a byte of information as two nibbles. Sometimes the set of all 256-byte values is represented as a 16×16 table, which gives easily readable hexadecimal codes for each value.

Four-bit computer architectures use groups of four bits as their fundamental unit. Such architectures were used in early microprocessors, pocket calculators and pocket computers. They continue to be used in some microcontrollers. In this context, 4-bit groups were sometimes also called characters[12] rather than nibbles.[1]

History

The term nibble originates from its representing "half a byte", with byte a homophone of the English word bite.[4] In 2014, David B. Benson, a professor emeritus at Washington State University, remembered that he playfully used (and may have possibly coined) the term nibble as "half a byte" and unit of storage required to hold a binary-coded decimal (BCD) digit around 1958, when talking to a programmer from Los Alamos Scientific Laboratory. The alternative spelling nybble reflects the spelling of byte, as noted in editorials of Kilobaud and Byte in the early 1980s. Another early recorded use of the term nybble was in 1977 within the consumer-banking technology group at Citibank. It created a pre-ISO 8583 standard for transactional messages between cash machines and Citibank's data centers that used the basic data unit 'nabble'.

Nibble is used to describe the amount of memory used to store a digit of a number stored in packed decimal format (BCD) within an IBM mainframe. This technique is used to make computations faster and debugging easier. An 8-bit byte is split in half and each nibble is used to store one decimal digit. The last (rightmost) nibble of the variable is reserved for the sign. Thus a variable which can store up to nine digits would be "packed" into 5 bytes. Ease of debugging resulted from the numbers’ being readable in a hex dump where two hex numbers are used to represent the value of a byte, as 16×16 = 28. For example, a five-byte BCD value of 31 41 59 26 5C represents a decimal value of +314159265.

Historically, there are cases where nybble was used for a group of bits greater than 4. In the Apple II microcomputer line, much of the disk drive control and group-coded recording was implemented in software. Writing data to a disk was done by converting 256-byte pages into sets of 5-bit (later, 6-bit) nibbles and loading disk data required the reverse.[13][14][15] Moreover, 1982 documentation for the Integrated Woz Machine refers consistently to an "8 bit nibble".[16] The term byte once had the same ambiguity and meant a set of bits but not necessarily 8, hence the distinction of bytes and octets or of nibbles and quartets (or quadbits). Today, the terms byte and nibble almost always refer to 8-bit and 4-bit collections respectively and are very rarely used to express any other sizes.

Binary and hexadecimal representation

A nibble can be represented in binary and hexadecimal as follows:

Binary vs Decimal vs Hexadecimal
BinaryDecimalHexadecimal
000000
000111
001022
001133
010044
010155
011066
011177
100088
100199
101010A
101111B
110012C
110113D
111014E
111115F

Low and high nibbles

The terms low nibble and high nibble are used to denote the nibbles containing, respectively, the less significant bits and the more significant bits within a byte. In graphical representations of bits within a byte, the leftmost bit could represent the most significant bit (MSB), corresponding to ordinary decimal notation in which the digit at the left of a number is the most significant. In such illustrations the four bits on the left end of the byte form the high nibble, and the remaining four bits form the low nibble.[17] For example,

ninety-seven = 9710 = (0110 0001)2 = 61hex

the high nibble is 01102 (6hex), and the low nibble is 00012 (1hex). The total value is high-nibble × 1610 + low-nibble (6 × 16 + 1 = 9710).

Extracting a nibble from a byte

A nibble can be extracted from a byte by doing a bitwise logical AND operation and optionally a bit shift depending on if the high or low nibble is to be extracted.

In C:

#define HI_NIBBLE(b) (((b) >> 4) & 0x0F)#define LO_NIBBLE(b) ((b) & 0x0F)

where b must be a variable or constant of an integral data type, and only the least-significant byte of b is used.

For example, HI_NIBBLE(0xAB)==0xA and LO_NIBBLE(0xAB)==0xB.

In Common Lisp:

(defun hi-nibble (b)  (ldb (byte 4 4) b))(defun lo-nibble (b)  (ldb (byte 4 0) b))

See also

References

External links