Digital Electronics · Lesson 5 of 33 · Numbers a computer understands

BCD, Gray code & ASCII

Same bits, different meanings

🔒 Free with Google sign-in: loading…

Key ideas

  • A code = an agreement on what bits mean
  • BCD · Gray · ASCII
  • BCD: 4 bits for each decimal digit
  • Easy to show on clocks and calculators
  • 1010 to 1111 are never used
  • Gray: only 1 bit changes per step
  • Binary 3 → 4 flips 3 bits
  • Used in knobs and rotary encoders
  • ASCII turns text into numbers
  • A = 65, a = 97
  • Upper vs lower case = one bit (32)

Worked example

  • Step 1: copy the first bit
  • Then XOR neighbours: same → 0, different → 1
  • 1011 in Gray = 1110
✗ Common mistakeA common mistake is writing B C D like plain binary. Twenty five in B C D is not one one zero zero one. Each digit gets its own four bits. Zero zero one zero, zero one zero one.
💡 Memory trickHere's the memory trick. B C D: one digit, four bits. Gray: one step, one bit. And ASCII: small letters are capital letters, plus thirty two.
RecapA code is an agreement on what bits mean. B C D gives each decimal digit four bits. In Gray code, only one bit changes per step. And ASCII stores letters as numbers.
❓ Quick questionQuick question. What is binary zero one one zero, in Gray code? The answer is in the next lesson.
See the answer in Lesson 6 →

Full lesson text

Read everything said in the video

Where you have seen itFirst, last lesson's question. In eight bit two's complement, one one one one one one one one is minus one twenty eight, plus one twenty seven. Minus one.

Where you have seen itNow picture a volume knob that reports its position in binary. Turning from seven to eight, all four bits must flip. But they never flip at exactly the same instant. For a split second, the chip can read fifteen, eleven, or nine. Wrong values.

Where you have seen itGray code fixes this. From seven to eight, only one bit changes. So there's never a wrong reading.

The ideaA code is just an agreement about what a bit pattern means. The same bits could be a number, or a letter. Today, three famous codes.

The ideaB C D, binary coded decimal, gives every decimal digit its own four bits. Fifty nine becomes zero one zero one, and one zero zero one. Compare that with plain binary. B C D makes it easy to show digits on clocks and calculators, and the patterns ten to fifteen are never used.

The ideaGray code is a way of counting where only one bit changes at each step. In binary, going from three to four flips three bits at once. In Gray code, it's always just one. That's why knobs and rotary encoders use it.

Worked exampleTo convert binary to Gray, copy the first bit. Then XOR each pair of neighbours. Same gives zero, different gives one. So one zero one one becomes one one one zero.

The ideaASCII turns text into numbers. Capital A is sixty five. Small a is ninety seven. Look closely. They differ by exactly one bit, worth thirty two. That's how a computer switches between upper and lower case.

Common mistakeA common mistake is writing B C D like plain binary. Twenty five in B C D is not one one zero zero one. Each digit gets its own four bits. Zero zero one zero, zero one zero one.

Memory trickHere's the memory trick. B C D: one digit, four bits. Gray: one step, one bit. And ASCII: small letters are capital letters, plus thirty two.

RecapLet's recap. A code is an agreement on what bits mean. B C D gives each decimal digit four bits. In Gray code, only one bit changes per step. And ASCII stores letters as numbers.

RecapQuick question. What is binary zero one one zero, in Gray code? The answer is in the next lesson.

Ready to test yourself? Practise real digital electronics interview questions, with model answers.

Practice questions →

← All 33 lessons of the Digital Electronics course

Last updated