1

I came across this in the book "Programming the Z80", it was an exercise question that wasn't answered.

GabrielOshiro
  • 7,986
  • 4
  • 45
  • 57
Abdelrahman Eid
  • 881
  • 2
  • 13
  • 28

1 Answers1

4

Because you're trying to represent decimal values with binary numbers. You can only use representations of numbers between 0 and 9.

Valid BCD 4-bit chunks:

0000 - 0
0001 - 1
0010 - 2
0011 - 3
0100 - 4
0101 - 5
0110 - 6
0111 - 7
1000 - 8
1001 - 9

Invalid BCD 4-bit chunks:

1010 - 10
1011 - 11
1100 - 12
1101 - 13
1110 - 14
1111 - 15

Examples:

0101 0011 - 53
1001 0111 - 97
1000 1001 0100 - 894
1010 0000 - (10)0 // We can't represent 10 in a single decimal digit

The values 10 to 15 would be valid in a BCH (binary coded hexadecimal) context. The previous invalid example would result in something like this:

1010 0000 - A0
Simon
  • 774
  • 4
  • 21