How Bit Patterns Carry Meaning
Digital equipment uses bits to represent numbers, positions, and messages. A display controller and a position sensor might assign different meanings to the same pattern. To interpret their signals, you need both the bits and the rule used to encode them. Binary codes provide those rules; choosing a code changes how conveniently you can display information, track position, or detect transmission errors.
Meaning and capacity
A binary code is a rule that assigns bit patterns to represented information. A codeword is one complete pattern assigned by that rule. Before decoding a word, identify its code, width, and bit order. Here, words are written with the most significant bit on the left.
For an unsigned positional binary number, each bit has a power-of-two weight:
The rightmost bit has weight 20=1. Moving left gives weights 2,4,8, and so on. For example, 1010 represents 8+2=10.
An n-bit word has 2n possible patterns. If you need M distinct messages, the capacity requirement is
This counts available patterns; a particular code may leave some unused. Unsigned binary uses every pattern and represents integers from 0 through 2n−1.
Decimal digits with 8421 BCD
In 8421 binary-coded decimal, or BCD, each decimal digit receives its own four-bit group. Within each group, the weights are 8,4,2,1. Only the patterns for digits 0 through 9 are valid; 1010 through 1111 are unused digit patterns.
To encode decimal 12, encode the digits separately:
so its BCD representation is 0001 0010. Reading those eight bits as one unsigned binary number instead gives 16+2=18. Grouping spaces help you see the digit boundaries, but the code specification supplies their meaning.
For a fixed-width field containing d decimal digits, BCD requires 4d bits, including groups for leading zeros.
Position labels and error checking
Binary-reflected Gray code assigns consecutive integer positions codewords that differ in exactly one bit. The two-bit sequence below illustrates this property.
This property is useful in position encoders because an adjacent-position transition changes only one code bit. Ordinary binary can change several bits at once, so unequal switching times can briefly produce an intermediate pattern. Gray code reduces that particular ambiguity; it does not guarantee error-free sensing.
To convert an unsigned binary word to reflected Gray code, copy its leftmost bit. Each remaining Gray bit is the exclusive OR, written ⊕, of the two adjacent binary bits:
Exclusive OR gives 1 when the inputs differ and 0 when they match. Gray code is not interpreted using ordinary positional weights.
A parity bit provides a different feature: error detection. Under the even-parity convention, choose the added bit so that the total number of 1s in the protected word is even. Data 1011 contain three 1s, so their even-parity bit is 1. Under odd parity, it would instead be 0.
Representation | Main purpose | Rule or constraint |
|---|---|---|
Unsigned binary | Represent an integer compactly | Uses power-of-two weights |
8421 BCD | Represent decimal digits separately | Uses four bits per digit |
Reflected Gray code | Label consecutive positions | Adjacent labels differ in one bit |
Added parity bit | Detect transmission errors | Constrains the total count of ones |
What to remember
- Identify the code before assigning meaning to a bit pattern.
- Use 2n to count available patterns; check which ones the code permits.
- Encode BCD one decimal digit at a time.
- Use Gray code for one-bit changes between adjacent position labels.
- State the parity convention and recognize its detection limits.
Example: Encoding a Rotary Selector Position
A rotary selector has 64 positions indexed from 0 through 63. Its controller uses a six-bit unsigned binary index, its display uses two 8421 BCD digits, and its position label uses six-bit binary-reflected Gray code. The selector is at position 58. Write all words most significant bit first.
For transmission, the controller appends one even-parity bit on the right of the eight BCD data bits. Parity covers all nine transmitted bits.
a) Find the six-bit unsigned binary index and verify that six bits cover the full position range.
Six bits provide enough distinct patterns for all selector positions:
Use the six positional weights 32,16,8,4,2,1. Decompose the current index as
The bits under those weights are therefore
As a check, five bits would provide only 25=32 patterns, which would not cover all 64 positions. The required index is 111010, using six bits.
b) Encode the displayed position as two 8421 BCD digits. How many data bits does this require compared with the unsigned index?
BCD encodes the decimal digits separately. The tens digit is 5, and the units digit is 8:
Place the tens group before the units group:
The width is
Thus, the BCD data word is 0101 1000, requiring 8−6=2 more bits than the unsigned index. Both groups are valid decimal-digit patterns.
c) Convert the unsigned index to its six-bit reflected Gray label.
Start with the original binary word 111010. Copy its leading bit. For every remaining Gray bit, use adjacent bits from that original binary word; do not substitute newly calculated Gray bits.
Reading the results in order gives the Gray label 100111. This label represents the same position index under the specified reflected Gray mapping; ordinary binary weights do not give its position value.
d) Determine the appended even-parity bit and write the complete BCD transmission.
Count the ones in the BCD data, rather than in the unsigned or Gray representation. The group 0101 contains ________ ones, and 1000 contains ________:
The data count is odd, so append parity bit p=1 to make the protected total even:
The complete nine-bit transmission is 0101 1000 1. The final bit checks the preceding BCD data; it is not another BCD digit. Counting four ones confirms that the word satisfies even parity.
A technician is documenting digital messages used for decimal displays, text, position labels and transmission checks. Match each code or check bit to its defining purpose.
Represents text characters using seven-bit patterns in its standard form.
Represents successive integer values with patterns that differ in exactly one bit position.
Makes the total number of 1s in a protected group even.
Represents each decimal digit separately using four positions with weights 8, 4, 2 and 1.
Even-parity bit
ASCII
Binary-reflected Gray code
8421 BCD
A data logger stores 256 readings. Each reading is an integer from 000 through 999, inclusive. Its original format uses three 8421 BCD digits per reading. A replacement format uses the smallest fixed-width unsigned binary word that can represent every permitted reading.
Both formats pack successive readings without gaps and add no headers or parity bits. One byte contains eight bits. How many bytes does the replacement format save for the complete set? Answer in bytes, to one decimal place.