2

For the number 6, if I need to represent it in 5421 code form, should I code it as 1001 or 0110? Why should I choose the one over the other?

Similarly for the number 5 in 2421, is it 1011 or 0101?

Edit 1:

In a weighted binary code, the name of the code indicates the weight assigned to each place.

So if the code is 8421, the number 9 would be written as 1001 (8*1 + 4*0 + 2*0 + 1*1=9). And the number 5 would be 0101 (8*0 +4*1 +2*0 +1*1=5). In each case, no other combination of weights add up to the values (9 and 5).

Edit 2:

But for 5421, can the number 5 be represented as 1000 (5*1+4*0+2*0+1*0=5) as well as 0101(5*0 + 4*1 + 2*0 + 1*1 = 5)? Which one should be chosen? Similarly for 2421, which one to choose between 1011 (2*1 + 4*0 + 2*1 + 1*1 = 5) and 0101 (2*0 + 4*1 + 2*0 + 1*1 = 5)?

Anupama
  • 21
  • 1
  • 3

1 Answers1

2

Codes like 5421 and 2421 are not unique, and this is one of their advantages. For example, 2421 is self-complementing: computing the 9-complement of a digit is the same as negating its bits. In textbooks you can find tables in which the authors choose one possible code for each digit, but this choice is arbitrary, and you might find different choices in different textbooks.

Let me also mention that BCD has been gradually losing favor, and I expect only old hardware to use anything other than 8421 (if at all). Most of the interest in BCD is historical, since modern architectures don't use BCD. I suspect that material about BCD is there mostly because of inertia, though BCD might still be used in conservative industries such as banking.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514