Number Systems and Codes
Beyond binary - octal, hexadecimal, BCD, and Gray code systems used throughout digital electronics.
While binary is the native language of digital circuits, engineers rarely work in raw binary. Hexadecimal provides compact notation for large binary values, BCD simplifies decimal display, and Gray code prevents errors in position sensing. Understanding these number systems and codes is essential for reading datasheets, debugging, and designing practical digital systems.
Objectives
- Convert between binary, octal, hexadecimal, and decimal
- Encode decimal numbers in BCD and identify invalid BCD codes
- Construct and read Gray code sequences
- Compare sign-magnitude, ones' complement, and two's complement representations
- Choose the appropriate number system for a given application
- Read hex values in datasheets and memory dumps
Key Takeaways
- Hexadecimal groups 4 bits per digit - the standard shorthand for binary in engineering
- Octal groups 3 bits per digit - used in Unix permissions and some older systems
- BCD encodes each decimal digit as 4 bits - used for displays and decimal arithmetic
- Gray code changes only 1 bit between adjacent values - prevents transition glitches
- Two's complement is the standard for signed integers: invert bits and add 1 to negate
- Choose the number system that best fits your application: hex for addresses, BCD for displays, Gray for encoders
Applications
- Memory Addressing: Hex is universally used for memory addresses, register values, and data dumps.
- Digital Displays: BCD drives 7-segment displays in clocks, meters, and calculators.
- Rotary Encoders: Gray code prevents position errors during mechanical transitions.
- Datasheets: IC registers and configuration values are specified in hex.
- Error Detection: Number system properties enable parity checks and error codes.
Practice Problems
Problem 1: Convert 0xB7 to binary and decimal.
Problem 2: Encode decimal 596 in BCD.
Problem 3: Convert binary 1101 to Gray code.
Problem 4: What decimal value does the 8-bit two's complement number 11100011 represent?
Problem 5: Is the BCD code 0111 1011 valid? Why or why not?
Problem 6: Convert octal 375 to hexadecimal.