IFT 211 · Digital Logic Design
Our notes
2 min readWhy codes?
A code is an agreed meaning for bit patterns. Number codes make decimal display easy; character codes let computers store text.
BCD (8421 code)
Each decimal digit is written as 4 bits. 739 = 0111 0011 1001. Patterns 1010 to 1111 are not used. BCD wastes some space (pure binary 739 needs 10 bits, BCD needs 12) but drives seven-segment displays, calculators and money calculations without rounding.
Excess-3 and 2421
- Excess-3: add 3 to each digit before coding: 5 → 1000. It is self-complementing (the 9's complement is found by flipping the bits).
- 2421: another weighted code with the same property.
Gray code
Neighbouring values differ in only one bit: 0 = 000, 1 = 001, 2 = 011, 3 = 010, 4 = 110, 5 = 111, 6 = 101, 7 = 100. Used in shaft-position encoders so a reading taken during a change is never far wrong, and in Karnaugh map labels.
- Binary to Gray: keep the first bit, then each Gray bit = this binary bit XOR the one before it. 1011 → 1110.
ASCII
The American Standard Code for Information Interchange uses 7 bits (128 characters): control codes 0 to 31, space 32, digits "0" to "9" at 48 to 57, "A" to "Z" at 65 to 90, "a" to "z" at 97 to 122. Lower case is upper case + 32 (one bit different). Extended 8-bit versions add accented letters, but they differ from one another.
EBCDIC
Extended Binary Coded Decimal Interchange Code, an 8-bit code from IBM mainframes. Letters are not in one continuous block, so programs that assume ASCII order fail on EBCDIC data. Still met in banking and older mainframe systems.
Unicode
One code for every writing system: Latin, Arabic, Chinese, and Nigerian letters such as ẹ, ọ, ṣ and the naira sign ₦ (U+20A6). Code points run to over a million. Stored as:
- UTF-8: 1 to 4 bytes per character; ASCII characters keep their one-byte codes. The standard for the web.
- UTF-16: 2 or 4 bytes (Windows, Java).
- UTF-32: always 4 bytes.
Worked example
Code the word "Hi5" in ASCII hex: H = 72 = 48₁₆, i = 105 = 69₁₆, 5 = 53 = 35₁₆, so 48 69 35.
Exams usually ask
- Code numbers in BCD, excess-3 and Gray; code text in ASCII.
- Compare ASCII, EBCDIC and Unicode.
Common mistake
Confusing the digit "5" (ASCII 53) with the number 5 (binary 101).
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
Read
-
Binary-coded decimal
(opens en.wikipedia.org in a new tab)
Wikipedia, Binary-coded decimal, CC BY-SA 4.0 · licence
-
Gray code
(opens en.wikipedia.org in a new tab)
Wikipedia, Gray code, CC BY-SA 4.0 · licence
-
ASCII
(opens en.wikipedia.org in a new tab)
Wikipedia, ASCII, CC BY-SA 4.0 · licence
-
NPTEL: Switching Circuits and Logic Design (IIT Kharagpur, Prof. Indranil Sengupta)
Video lectures, many hours in all: watch on Wi-Fi where you can.
(opens nptel.ac.in in a new tab)
NPTEL, NPTEL: Switching Circuits and Logic Design (IIT Kharagpur, Prof. Indranil Sengupta), CC BY-NC-SA 4.0 · licence
Watch
-
Best pick Binary Coded Decimal (BCD) Code
17 min · ≈ 77 MB · about ₦43
(opens youtube.com in a new tab)
-
Gray Code Explained | Gray code to Binary and Binary to Gray code Conversion
13 min · ≈ 59 MB · about ₦33
(opens youtube.com in a new tab)
-
ASCII Code and Binary
8 min · ≈ 36 MB · about ₦20
(opens youtube.com in a new tab)
-
Digital Logic | Binary codes (ASCII, Gray, BCD)
19 min · ≈ 86 MB · about ₦48
(opens youtube.com in a new tab)
Practise
We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.