Introduction
Open in the Padhaiko app1.1 Digital versus analog signals
An analog signal can take any value in a continuous range and changes smoothly with time (a microphone voltage, a temperature sensor output). A digital signal takes only a few discrete values, almost always two: 0 and 1.
| Feature | Analog | Digital |
|---|---|---|
| Values | Continuous, infinitely many | Discrete, usually two levels |
| Noise | Noise adds to the signal and cannot be removed | Small noise is ignored by the threshold, so data is regenerated cleanly |
| Storage | Hard to store without loss | Easy to store and copy exactly |
| Accuracy | Limited by component tolerance | Increased by adding more bits |
| Design | Complex, hard to automate | Built from standard gates, easy to automate |
| Example | Audio amplifier, thermometer | Computer, calculator, digital watch |
A digital system processes information that is represented by binary numbers. To use real-world analog quantities, an ADC (analog to digital converter) turns the input into bits and a DAC turns the result back into a voltage.
1.2 Logic level diagram
In a digital circuit the two logic values are represented by two voltage ranges. With positive logic, the higher range means HIGH = 1 and the lower range means LOW = 0. The range between them is the forbidden (undefined) region: a voltage there may be read as either value, so a good circuit never leaves it except while switching.
| Voltage range | Region | Meaning |
|---|---|---|
| 5 V down to 2.0 V | HIGH input range | Read as logic 1 ( min = 2.0 V) |
| 2.0 V to 0.8 V | Forbidden region | Undefined, may be read as either |
| 0.8 V down to 0 V | LOW input range | Read as logic 0 ( max = 0.8 V) |
A TTL output guarantees at least 2.4 V for HIGH () and at most 0.4 V for LOW (). The 0.4 V difference between output and input limits is the noise margin: V and V. A noise spike smaller than this margin cannot flip the logic value.
1.3 Digital integrated circuits (ICs)
A digital IC packs many logic gates on a single silicon chip. ICs are grouped by the number of gates (complexity) and by the technology used.
| Scale | Gates per chip | Typical examples |
|---|---|---|
| SSI (small scale) | up to 12 | Basic gates, flip-flops |
| MSI (medium scale) | 12 to 99 | Counters, decoders, multiplexers, registers |
| LSI (large scale) | 100 to 9999 | Small memories, 8-bit microprocessor |
| VLSI (very large scale) | 10000 to 99999 | Large memories, microprocessors |
| ULSI (ultra large scale) | 100000 and more | Modern processors |
The two main logic families are TTL (transistor-transistor logic, bipolar, 74xx series, 5 V supply) and CMOS (complementary MOSFET, 74Cxx or 74HCxx, very low static power). Chapter 8 compares them in detail.
1.4 Clock triggering systems
A clock is a periodic square wave that tells a sequential circuit when to change state. A circuit can be triggered in two ways.
- Level triggering: the circuit responds for the whole time the clock is at HIGH (or LOW). Input changes during that time can pass through.
- Edge triggering: the circuit responds only at the instant of a clock transition. A positive (rising) edge is the 0 to 1 transition and a negative (falling) edge is the 1 to 0 transition.
Edge triggering is safer because the inputs are sampled only for a very short moment. The frequency of the clock is and the duty cycle is the ratio of HIGH time to the period, .
For example a clock of period has kHz.
1.5 Digital system applications
Digital systems are everywhere because they are accurate, cheap and programmable.
- Computing: computers, microcontrollers, memories.
- Communication: mobile phones, digital TV and radio, internet routers.
- Instrumentation and control: digital multimeters, frequency counters, industrial controllers.
- Consumer products: digital watches, calculators, cameras, washing machines.
- Medicine and transport: digital ECG, CT scanners, car engine control units.
1.6 Digital codes and conversions
1.6.1 Decimal, binary, octal and hexadecimal codes
A number system with radix (base) r uses digits to , and the digit at position has weight .
| System | Radix | Digits | Used for |
|---|---|---|---|
| Decimal | 10 | 0 to 9 | Everyday arithmetic |
| Binary | 2 | 0, 1 | Digital hardware |
| Octal | 8 | 0 to 7 | Short form of binary (3 bits per digit) |
| Hexadecimal | 16 | 0 to 9, A to F | Short form of binary (4 bits per digit) |
Conversion methods
- Binary to decimal: add the weights of the 1 bits.
- Decimal to binary (integer part): divide repeatedly by 2 and read the remainders from bottom to top.
- Decimal to binary (fraction part): multiply repeatedly by 2 and read the integer parts from top to bottom.
- Binary to octal or hex: group bits in threes or fours starting at the binary point, and replace each group by its digit.
1.6.2 BCD code
BCD (binary coded decimal) writes each decimal digit as its own 4-bit binary number. So becomes . The codes 1010 to 1111 are invalid in BCD. BCD is easy to display but needs more bits than pure binary (two digits take 8 bits, while 47 needs only 6 bits in binary).
1.6.3 Excess-3 code
Excess-3 is BCD plus 3 (0011) added to each digit, so decimal 0 is 0011 and 9 is 1100. It is self-complementing: the 1's complement of the code of a digit is the code of its 9's complement (for example 2 is 0101 and 7 is 1010), which makes decimal subtraction easy.
1.6.4 Gray code
Gray code is a unit-distance code: only one bit changes between consecutive numbers. It is used in shaft encoders and K-maps to avoid glitches.
- Binary to Gray: the MSB stays the same; each next Gray bit is the XOR of the binary bit and the binary bit on its left.
- Gray to binary: the MSB stays the same; each next binary bit is the XOR of the previous binary bit and the current Gray bit.
| Decimal | Binary | BCD | Excess-3 | Gray (4-bit) |
|---|---|---|---|---|
| 0 | 0000 | 0000 | 0011 | 0000 |
| 1 | 0001 | 0001 | 0100 | 0001 |
| 2 | 0010 | 0010 | 0101 | 0011 |
| 3 | 0011 | 0011 | 0110 | 0010 |
| 4 | 0100 | 0100 | 0111 | 0110 |
| 5 | 0101 | 0101 | 1000 | 0111 |
| 6 | 0110 | 0110 | 1001 | 0101 |
| 7 | 0111 | 0111 | 1010 | 0100 |
| 8 | 1000 | 1000 | 1011 | 1100 |
| 9 | 1001 | 1001 | 1100 | 1101 |
1.6.5 Examples of code conversions
1.7 Alphanumeric codes: ASCII code and EBCDIC code
Computers must also store letters, digits and symbols, so each character is given a binary code.
| Feature | ASCII | EBCDIC |
|---|---|---|
| Full form | American Standard Code for Information Interchange | Extended Binary Coded Decimal Interchange Code |
| Bits | 7 bits (128 characters), 8 bits in extended form | 8 bits (256 characters) |
| Used by | Almost all PCs and the internet | IBM mainframes |
| Digit 0 | 0110000 (30H) | 11110000 (F0H) |
| Letter A | 1000001 (41H) | 11000001 (C1H) |
| Letter a | 1100001 (61H) | 10000001 (81H) |
| Letters contiguous? | Yes, A to Z are consecutive codes | No, there are gaps between I, J and R, S |
In ASCII the lower-case letter code is the upper-case code plus 32 (20H), the digit has code , and codes 0 to 31 are control characters such as carriage return (0DH) and line feed (0AH).
1.8 1's complement and 2's complement
For an -bit binary number:
- 1's complement: invert every bit.
- 2's complement: 1's complement plus 1. Quick method: copy bits from the right up to and including the first 1, then invert all remaining bits.
The 2's complement is used to represent negative numbers and to turn subtraction into addition: .
- If there is a carry out of the MSB, the result is positive and the carry is discarded.
- If there is no carry, the result is negative and is in 2's complement form.
1.9 Signed number representation
The leftmost bit is the sign bit: 0 means positive and 1 means negative. Three methods exist for an -bit number.
| Method | How -N is formed | Range | Zero |
|---|---|---|---|
| Sign-magnitude | Set the sign bit, keep the magnitude | to | Two zeros (+0 and -0) |
| 1's complement | Invert all bits of +N | to | Two zeros |
| 2's complement | Invert all bits and add 1 | to | One zero |
For 8 bits, 2's complement covers to . Overflow occurs when two numbers of the same sign give a result of the opposite sign.
Worked Examples
1
Convert the decimal number into binary, octal and hexadecimal.
Integer part by repeated division by 2. rem 0; rem 0; rem 1; rem 1; rem 1; rem 0; rem 0; rem 1. Reading the remainders from bottom to top gives .
Fraction part by repeated multiplication by 2. (digit 1); (digit 0); (digit 1). So and the full number is .
Group the bits for octal and hexadecimal.
Octal (groups of 3): . Hexadecimal (groups of 4): .
2
For the decimal number write the BCD code and the excess-3 code, and for the binary number find the Gray code. Then convert the Gray code back to binary.
BCD of 47. Code each digit in 4 bits: and , so in BCD.
Excess-3 of 47. Add 3 to each digit first: and . Hence in excess-3.
Binary 1011 to Gray. Keep the MSB: . Then , , . The Gray code is .
Gray 1110 to binary. Keep the MSB: . Then , , . The binary number is (so are a pair).
BCD of 47 = 0100 0111; excess-3 of 47 = 0111 1010; Gray of 1011 = 1110; binary of Gray 1110 = 1011.
3
Using 8-bit 2's complement arithmetic, evaluate and then . Give each result in binary and decimal.
Write the numbers in 8 bits. and .
25 - 37. The 2's complement of : invert to get and add 1 to get (which is ). Now with no carry out. No carry means the answer is negative and is stored in 2's complement form. Its magnitude is the 2's complement of : invert to and add 1 to get . So the result is .
37 - 25. The 2's complement of : invert to get and add 1 to get . Then . There is a carry out, so the result is positive: discard the carry and read .
(negative, no carry); (carry discarded).
Exercises
Exercises: Introduction
Distinguish between analog and digital signals. State three advantages of digital systems.
An analog signal varies continuously and can take infinitely many values; a digital signal has only discrete levels (normally two).
Advantages of digital systems: (i) noise immunity, because any voltage above the threshold is regenerated as a clean 1 or 0; (ii) easy and exact storage and copying of data; (iii) easy design and automation with standard gates, and higher accuracy by adding more bits.
Analog: continuous values; digital: discrete (0 and 1). Digital systems are noise immune, easy to store, accurate and programmable.
Convert into decimal and into hexadecimal.
Integer part: . Fraction: . So the decimal value is .
Hexadecimal: group in fours from the point: (pad the fraction with a zero) .
Write the BCD code for the decimal number and explain why BCD needs more bits than binary. Also write its excess-3 code.
BCD codes each digit separately: , , , so (12 bits).
In pure binary needs only 9 bits. BCD needs 4 bits per digit and wastes the six codes 1010 to 1111, hence more bits.
Excess-3: add 3 to each digit first: , and , so the code is .
BCD of 259 = 0010 0101 1001 (12 bits against 9 bits in binary); excess-3 = 0101 1000 1100.
Write the 4-bit Gray code sequence from decimal 6 to 10 and show that only one bit changes between neighbours.
Use . For 6 (): . For 7 (): . For 8 (): . For 9 (): . For 10 (): .
Neighbouring pairs: (bit 0), (bit 3), (bit 0), (bit 1). Exactly one bit differs in every step.
Gray codes: 6 = 0101, 7 = 0100, 8 = 1100, 9 = 1101, 10 = 1111.
Represent and in 8-bit sign-magnitude, 1's complement and 2's complement. State the range of an 8-bit 2's complement number.
in all three systems.
: sign-magnitude sets the sign bit, giving . The 1's complement inverts all bits, giving . The 2's complement adds 1 to that, giving .
For the 2's complement range is to , that is to .
: sign-magnitude , 1's complement , 2's complement ; range to .