Overview
Readings Floyd, Digital Fundamentals ch. 1–2 · weeks 1–2
Why do computers work in binary? Because it’s the most reliable way to store and move information through a noisy, imperfect physical world. A wire can easily be “clearly high” or “clearly low” even when its voltage wobbles a bit. Distinguishing ten different voltage levels for the ten decimal digits would be far more fragile.
So everything digital comes down to two levels, HIGH and LOW, standing for 1 and 0. This chapter follows that idea in two directions:
- In time: how a 1 or 0 looks as a voltage on a wire, how a stream of bits becomes a waveform, and how to measure one on an oscilloscope.
- In meaning: how a string of bits can represent a number, in binary, in its shorthand hexadecimal, in BCD, and how 1’s and 2’s complement let the same bits represent negative numbers.
Notes
Logic levels
A digital signal is either HIGH or LOW. Each level is a range of voltages, not one exact value, with an invalid gap in between:
| Range (5 V logic) | Meaning |
|---|---|
| to | HIGH, binary 1 |
| to | Invalid (only passed through during a transition) |
| to | LOW, binary 0 |
Why ranges? Real voltages are never exact. Wires pick up noise, components vary, and a “5 V” output might really be 4.6 V. If 1 meant exactly 5 V, almost nothing would count as a 1. With ranges, a signal can wander around quite a bit and still be read correctly. That robustness is the whole advantage of digital over analog: as long as the noise doesn’t push a signal across into the other range, the information arrives perfectly.
Why the gap? It’s a buffer zone. If 1 and 0 met at a single threshold, a signal sitting right at that threshold could flicker between them with the tiniest bit of noise. The gap means a valid 1 and a valid 0 are always well separated. A signal only passes through the gap briefly while switching.
Example 1.1: Classifying voltages as logic levels
Using the 5 V logic ranges above, classify (a) V, (b) V and (c) V. Then, (d) a gate drives a HIGH of V and noise pulls it down by V. Is the bit still read correctly?
Show answerHide answer
- (a) V is between V and V, so it is a valid HIGH (1).
- (b) V is between V and V, so it is invalid. A circuit reading this can’t tell what the bit is.
- (c) V is below V, so it is a valid LOW (0).
- (d) V, which falls in the invalid gap, so the bit is lost. A noise dip of V or less would have left it at V or more and it would still read as a 1.
The wider the valid ranges and the smaller the noise, the more reliably a bit arrives.
A single binary digit is a bit. Using HIGH = 1 and LOW = 0 is called positive logic, which is what this course uses.
Digital waveforms
A digital waveform is a plot of a signal’s level over time as it switches between LOW and HIGH. One trip up and back down is a pulse:
- Positive-going pulse: normally LOW, goes HIGH, then back to LOW.
- Negative-going pulse: normally HIGH, goes LOW, then back to HIGH.
- The first edge of a pulse is the leading edge and the second is the trailing edge. On a positive-going pulse, the leading edge is the rising edge and the trailing edge is the falling edge.
A waveform is periodic if its pulses repeat at a fixed interval (a clock), and non-periodic if they don’t (a data signal, which follows whatever the data is). A periodic waveform is described by:
Figure 1.1: The parts of a periodic pulse waveform.
| Quantity | Symbol | Meaning |
|---|---|---|
| Period | Time for one full cycle (one HIGH part + one LOW part) | |
| Frequency | Cycles per second (Hz). | |
| Pulse width | Time the pulse spends HIGH | |
| Duty cycle | — | Fraction of the period spent HIGH, as a %: |
| Amplitude | Voltage from LOW to HIGH (, peak-to-peak) |
because frequency counts cycles per second and the period is seconds per cycle. They’re the same information turned upside down: a 1 ms period means 1000 cycles fit in a second. A square wave is the special case with a 50% duty cycle, HIGH and LOW for equal times.
Example 1.2: Period, frequency and pulse width
(a) A clock runs at MHz with a duty cycle. Find , and the LOW time. (b) A waveform has a period of ms. What is its frequency?
Show answerHide answer
(a)
(b)
A shorter period always means a higher frequency. The duty cycle only changes how the period is split between HIGH and LOW, not how long it is.
Waveforms carry binary data
To send a sequence of bits down one wire, you take turns: each bit gets an equal slice of time called the bit time, and during its slice the wire is HIGH for a 1 or LOW for a 0.
But how does the receiver know where one slice ends and the next begins? Two 1s in a row look like one long HIGH. That’s what the clock is for. Every waveform in the system is synchronized to a periodic clock signal whose period is one bit time, so the clock’s ticks mark the slice boundaries. To read the bits off a waveform, check its level once during each clock period. The clock is a shared metronome everyone in the circuit keeps time to.
Example 1.3: Bit time and a serial waveform
A serial line is clocked at MHz and sends the 8 bits , one per clock period. Find the bit time and the total time, and describe the waveform.
Show answerHide answer
Consecutive equal bits merge into one longer level, so the line is: HIGH for s (1), LOW for s (0), HIGH for s (11), LOW for s (00), HIGH for s (1), and LOW for s (0). Those add to s. Without the clock, a receiver seeing a s HIGH couldn’t tell whether it was one long bit or two 1s.
Reading an oscilloscope
An oscilloscope draws a voltage against time on a screen marked out in a grid of divisions. The grid itself has no units. The two settings tell you what one division is worth:
- Vertical (V/div): volts per division. Amplitude = (number of divisions tall) × V/div.
- Horizontal (time/div): time per division. Period = (number of divisions per cycle) × time/div.
It’s just like the scale on a map: count the squares, multiply by what each square represents. To sketch a waveform on a scope you go the other way and divide: divisions = value ÷ (value per division).
Example 1.4: Reading a scope screen
A square wave on a scope is 4 divisions tall and one cycle spans 5 divisions, of which the HIGH part takes 2. The scope is set to 0.5 V/div and 20 µs/div. Find , , , , and the duty cycle.
Show answerHide answer
- Amplitude:
- Period and frequency:
- Pulse width and duty cycle:
A 40% duty cycle means this isn't a "square" wave, even if it looks like one. Square means 50%.
Example 1.5: Sketching a waveform on a scope
Sketch a pulse waveform with , , and a 60% duty cycle, on a scope set to 500 mV/div and 10 ns/div. How many divisions does each part take?
Show answerHide answer
- Period: , so one cycle spans divisions.
- Amplitude: divisions tall.
- Pulse width: , so the HIGH part spans divisions and the LOW part the other 1.6.
Check it with the oscilloscope above: set 25 MHz, 60%, 2 V, 500 mV/div, 10 ns/div.
Try it: set a frequency, duty cycle and amplitude, then change the scope settings and see how many divisions each part takes up.
Decimal and binary numbers
Decimal and binary are both positional (weighted) number systems: what a digit is worth depends on where it sits. In decimal, the 5 in 568 means 500 because it’s in the hundreds place. Each position is worth the base times the position to its right:
- Decimal (base 10): weights are powers of 10.
- Binary (base 2): weights are powers of 2, so each bit is worth double the one to its right.
Binary uses only the digits 0 and 1 for the same reason decimal uses 0–9: a position “fills up” when it reaches the base. In decimal, 9 + 1 doesn’t fit in one place, so it rolls over to 10. In binary that happens already at 1 + 1 = 10.
- The rightmost whole-number bit is the LSB (least significant bit), weight . It changes the value the least.
- The leftmost bit is the MSB (most significant bit), the one with the biggest weight.
- Bits right of the binary point have fractional weights
How far bits can count. Each bit has 2 choices, so bits have possible patterns. Starting from 0, those patterns cover to (the “−1” is because zero uses up one pattern). 4 bits count 0 to 15. Every extra bit doubles the range.
| Bits | (combinations) | Largest number, |
|---|---|---|
| 1 | 2 | 1 |
| 2 | 4 | 3 |
| 3 | 8 | 7 |
| 4 | 16 | 15 |
| 5 | 32 | 31 |
| 6 | 64 | 63 |
| 7 | 128 | 127 |
| 8 | 256 | 255 |
| 9 | 512 | 511 |
| 10 | 1024 | 1023 |
Example 1.6: Range of an -bit number
What range of numbers can 7 bits count? How many bits are needed to count up to 300?
Show answerHide answer
- 7 bits: , so 0 to 127 (128 different values).
- Up to 300: 8 bits only get to , which isn’t enough. 9 bits get to , so you need 9 bits.
Converting between binary and decimal
Binary → decimal: each 1 bit contributes its weight and each 0 contributes nothing, so add up the weights of the 1s.
Example 1.7: Binary to decimal
Convert and to decimal.
Show answerHide answer
- : the 1s sit at weights 64, 16, 8, 2, 1.
- : the whole part is . The fraction has 1s at and :
Decimal → binary, two ways:
- Sum of weights: find the binary weights that add up to the number, then put a 1 in those positions. Start from the largest weight that fits and work down.
- Repeated division by 2: keep dividing by 2 until the quotient is 0. The remainders are the bits, with the first remainder = LSB and the last remainder = MSB.
Why repeated division works. Dividing a binary number by 2 shifts every bit one place right, and the bit that falls off the end is the remainder. So the first division’s remainder is the original LSB (it also tells you whether the number is odd). The quotient is the number with that bit removed, and dividing it again peels off the next bit. Each division reveals one more bit, from right to left, which is why the remainders come out LSB first.
| Division | Quotient | Remainder |
|---|---|---|
| 78 | 0 (LSB) | |
| 39 | 0 | |
| 19 | 1 | |
| 9 | 1 | |
| 4 | 1 | |
| 2 | 0 | |
| 1 | 0 | |
| 0 | 1 (MSB) |
Reading the remainders bottom to top: .
Example 1.8: Decimal to binary
Convert 74 using sum of weights, and 173 using repeated division by 2.
Show answerHide answer
Sum of weights: the largest weight that fits in 74 is 64, leaving 10 = 8 + 2.
Repeated division:
| Division | Quotient | Remainder |
|---|---|---|
| 86 | 1 (LSB) | |
| 43 | 0 | |
| 21 | 1 | |
| 10 | 1 | |
| 5 | 0 | |
| 2 | 1 | |
| 1 | 0 | |
| 0 | 1 (MSB) |
Reading bottom to top: . Check: ✓
Binary addition and subtraction
Binary arithmetic follows exactly the same column-by-column method you learned for decimal. Only the rollover point changes: a column overflows at 2 instead of 10.
| Addition | Result | Subtraction | Result |
|---|---|---|---|
| (sum 0, carry 1) | (0 − 1 with a borrow) | ||
| (sum 1, carry 1) |
, and 2 is written in binary, so you write 0 and carry 1, just as 7 + 5 = 12 means “write 2, carry 1” in decimal. The row is what happens in a column that also received a carry.
You only need to borrow when subtracting a 1 from a 0. It takes 1 from the next column to the left, and since each column is worth twice the one to its right, that borrowed 1 is worth 2 in the current column. Then . (In decimal a borrow is worth 10, for the same reason.)
Example 1.9: Binary addition and subtraction
Find (a) and (b) .
Show answerHide answer
(a) Work right to left, carrying when a column adds to 2 or more:
- Column 0:
- Column 1: , write 0, carry 1
- Column 2: , write 0, carry 1
- Column 3: , write 0, carry 1 into a new column
Check: ✓
(b) Borrow when subtracting 1 from 0:
- Column 0: needs a borrow. The column-1 bit is also 0, so the borrow comes from column 2, leaving column 2 = 0 and column 1 = 1. Column 0 becomes .
- Column 1:
- Column 2: needs a borrow from column 3, giving and column 3 = 0.
- Column 3:
Check: ✓
1’s and 2’s complement
These are ways of representing negative numbers using only bits, since there’s no ”−” sign in hardware (more in Ch 5).
- 1’s complement: flip every bit (0 → 1, 1 → 0). In hardware that’s just an inverter on each bit.
- 2’s complement: the 1’s complement plus 1.
Why 2’s complement means “negative”. Picture a car’s odometer with only 4 digits. Roll it back one from 0000 and it shows 9999. In that world, 9999 behaves exactly like −1: add 1 and you’re back to 0000. Binary registers work the same way. With 4 bits, , but there’s no room for the fifth bit, so it’s lost and the answer is . So acts like .
In general, the 2’s complement of in bits is . Add it to and you get exactly , a 1 followed by zeros, which wraps around to zero. “The number that adds to to give zero” is the definition of . For example, in 4 bits, and its 2’s complement is . As an unsigned number that’s 13, but , and . So stands for .
Example 1.10: Finding a negative number in 4 bits
What bit pattern represents in 4-bit 2’s complement, and how can you check it?
Show answerHide answer
Start from . Flip the bits to get , then add 1:
Check: should be zero. , and the fifth bit doesn’t fit in 4 bits, so the result is ✓. (As an unsigned number is , matching .)
Why “flip and add 1” gives . Flipping every bit of gives , because plus its flipped version is all 1s, which is . Adding 1 makes it .
Shortcut for 2’s complement: starting at the LSB, copy the bits up to and including the first 1, then flip all the bits after it.
This works because of what “add 1” does after flipping. The trailing 0s of the original became 1s when flipped, and adding 1 turns them back to 0s with a carry rippling left. The carry stops at the position of the first original 1, which had become 0 and now becomes 1 again. Everything to the left of that stays flipped.
Example 1.11: 1’s and 2’s complements
Find the 1’s and 2’s complements of .
Show answerHide answer
- 1’s complement: flip every bit:
- 2’s complement: add 1:
- Check with the shortcut: copy up to the first 1 from the right (), flip the rest (): ✓
Hexadecimal
Long binary numbers are hard for people to read and easy to copy wrong. Hexadecimal (base 16) is a compact shorthand. Since , each hex digit stands for exactly 4 bits, so converting is just grouping, with no arithmetic. The digits are 0–9, then A–F for 10–15.
| Hex | Binary | Decimal | Hex | Binary | Decimal |
|---|---|---|---|---|---|
| 0 | 0000 | 0 | 8 | 1000 | 8 |
| 1 | 0001 | 1 | 9 | 1001 | 9 |
| 2 | 0010 | 2 | A | 1010 | 10 |
| 3 | 0011 | 3 | B | 1011 | 11 |
| 4 | 0100 | 4 | C | 1100 | 12 |
| 5 | 0101 | 5 | D | 1101 | 13 |
| 6 | 0110 | 6 | E | 1110 | 14 |
| 7 | 0111 | 7 | F | 1111 | 15 |
- Binary → hex: split into groups of 4 starting from the right (pad the leftmost group with 0s), then replace each group.
- Hex → binary: replace each hex digit with its 4 bits.
- Hex → decimal: multiply each digit by its weight () and add them up, or go through binary.
- Decimal → hex: go through binary, or divide by 16 over and over (the remainders are the hex digits, first one = least significant), for the same reason repeated division by 2 works.
Group from the right because the right end is where the place values start (). Grouping from the left would misalign every group whenever the length isn’t a multiple of 4.
Example 1.12: Binary and hexadecimal
Convert to hex, and to binary.
Show answerHide answer
- Group by 4 from the right, padding the left group:
- Replace each hex digit:
Counting keeps going past F like it does in decimal: …, E, F, 10, 11, …, 1F, 20, … Two hex digits (8 bits, one byte) get you to , three get you to , and four get you to . One byte is always exactly two hex digits, which is why hex is the standard way to show memory contents.
Example 1.13: Hex and decimal
Convert to decimal and to hex.
Show answerHide answer
-
Hex → decimal: , so
-
Decimal → hex by dividing by 16:
- remainder
- remainder
- remainder
Reading the remainders last to first: . Check: ✓
Binary coded decimal (BCD)
BCD (the 8421 code) takes a different approach: instead of converting the whole number to binary, it writes each decimal digit separately as its own 4-bit group, with weights 8, 4, 2, 1.
- Decimal → BCD: replace each decimal digit with 4 bits.
- BCD → decimal: split into 4-bit groups from the right and read each as a digit.
- Only – (0–9) are used. The six codes to are invalid in BCD, since no single decimal digit is bigger than 9.
Why use it? Because it keeps the decimal digits separate. A digital clock or calculator display needs to show each decimal digit on its own segment display, and with BCD each 4-bit group drives one digit directly. Converting pure binary to separate decimal digits takes real computation. The cost is wasted space: 4 bits could represent 16 values but BCD only uses 10 of them, so BCD needs more bits than plain binary for the same number.
BCD is not the same as binary. in binary is (one number), but in BCD it's (a 3, then a 5).
Example 1.14: BCD
(a) Write 4073 in BCD. (b) Convert the BCD code to decimal. (c) Is a valid BCD number?
Show answerHide answer
- (a) One 4-bit group per digit:
- (b) Group from the right:
- (c) No. is 11, which isn’t a decimal digit, so it’s one of the six invalid codes.
Try it: click the bits to build a number and see it in every form from this chapter. (The signed rows make more sense after Ch 5.)
Key formulas
Waveforms
- : frequency, in hertz (Hz)
- : period, the time for one full cycle, in seconds
- : pulse width, the time spent HIGH in each cycle
Reading a scope
- Use V/div for amplitudes and time/div for and .
Binary numbers
- : the decimal value
- : the bit in position (0 or 1). is the LSB, and are the bits right of the binary point.
- : number of bits
Complements (of an -bit number )
- : 1’s complement of (flip every bit)
- : 2’s complement of (flip every bit, then add 1)
Common mistakes
- Reading the remainders of repeated division top to bottom. The first remainder is the LSB.
- Grouping binary into 4s for hex from the left. Always group from the right (the binary point) and pad on the left.
- Mixing up BCD and binary. BCD encodes each decimal digit separately.
- Forgetting the +1 for the 2’s complement, or doing the shortcut from the wrong end (it starts at the LSB).
- Calling any 0/1 waveform a “square wave”. It’s only square at a 50% duty cycle.
- Using the total number of scope divisions instead of the number for one cycle when finding .