EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: dentaku on January 09, 2014, 11:50:41 pm

Title: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: dentaku on January 09, 2014, 11:50:41 pm
I'm wondering why BCD is organized the way it is.

Why isn't the number one 1000 instead of 0001 and two is 0010 and not 0100 etc?

In other words why are the bits ordered 8-4-2-1 and not 1-2-4-8?
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: AlfBaz on January 09, 2014, 11:56:18 pm
probably the same reason the decimal number 192 is written as 192 rather than 291
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: c4757p on January 09, 2014, 11:56:43 pm
Binary: 8 4 2 1
Decimal: 1000 100 10 1
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: peter.mitchell on January 10, 2014, 12:34:16 am
MSB/MSD comes first in most number systems...
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: idpromnut on January 10, 2014, 12:42:04 am
Why isn't the number one 1000 instead of 0001 and two is 0010 and not 0100 etc?

I suppose for the same reason that we order decimal numbers the same way:  1000s, 100s, 10s, 1:   8s, 4s, 2s, 1s in binary
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: Strada916 on January 10, 2014, 01:12:01 am
elementary my dear Watson elementary!  :-/O

as explained above.
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: TonyGreene on January 10, 2014, 01:17:21 am
google Endianness and you will find it, it can go either way - depends on how the hardware is designed
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: Rigby on January 10, 2014, 01:17:54 am
Well in computing it can go either way, and it often will, even within the same system.

Intel CPUs as an example are "little endian" meaning that the bit with the lowest address is the least significant digit.  So, in your example, this would be 1-2-4-8.

ARM CPUs were big-endian (8-4-2-1) but as of version 3 they are now bi-endian, meaning that you can control the endianness via software configuration to suit your own needs.  Very handy.

When you design hardware that is implemented on an FPGA, it is very easy to swap endianness or to use little endian everywhere when you wanted big endian.

In short, both types are used all over the freaking place in digital systems.
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: george graves on January 10, 2014, 01:19:37 am
EDIT:  Ah, I thought so.

Doesn't that refer to little-endian vs big-endian? Or is that something different?
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: sleemanj on January 10, 2014, 01:26:50 am
I'm wondering why BCD is organized the way it is.

Why isn't the number one 1000 instead of 0001 and two is 0010 and not 0100 etc?

0001 means we don't care about how many pointless bits before the first 1 there are, and we don't know how many bits wide the field is (only how many actually useful bits were given), this gives more efficient operations, consider a shift register with reset:

To represent 1 as "1000" is RESET-Shift1-Shift0-Shift0-Shift0-Latch
To represent 1 as "0001" is RESET-Shift1-Latch

(well, of course, that depends on how you take the data out of the register, but at least in my mind, it always goes "LSB" as the last shift).
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: dentaku on January 10, 2014, 03:19:57 am
Great, I've heard about LSB and endian-ness all my life but It was probably the 90's since I ever paid attention to what it meant.

I can see how it's like decimal numbers with the 1000's first then the 100's then the 10's then 1's when you have a 4 digit number.
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: digsys on January 10, 2014, 03:33:16 am
Endianess refers to the BYTE order. The BITS in a byte remain MSB-LSB in all systems.
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: vk6zgo on January 10, 2014, 04:54:18 am
Endianess refers to the BYTE order. The BITS in a byte remain MSB-LSB in all systems.

I always thought it referred to the state of being of an Existentialist Native American! ;D
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: han on January 10, 2014, 05:18:48 am
hi,

yesterday my friend told me that he use BCD sequence like : 20-10-8-4-2-1 .
i don't remember there any bigger number than 8 in BCD in the text book?
could some body explanin? or even use it?
or he just make a mistake...
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: digsys on January 10, 2014, 05:32:20 am
Quote from: han
yesterday my friend told me that he use BCD sequence like : 20-10-8-4-2-1 .
i don't remember there any bigger number than 8 in BCD in the text book?
could some body explanin? or even use it?
or he just make a mistake...
Yup, probably a small glitch in his brain .. happens :-)
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: Dave on January 10, 2014, 05:38:40 am
yesterday my friend told me that he use BCD sequence like : 80-40-20-10-8-4-2-1 .
i don't remember there any bigger number than 8 in BCD in the text book?
could some body explanin? or even use it?
That's the tens digit.
BCD is about coding decimal digits into binary code, hence the name (binary coded decimal). If you have a two digit decimal number, you need 8 BCD bits.
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: han on January 10, 2014, 05:54:28 am

so the number will continuous to ..... 800-400-200-100-80-40-20-10-8-4-2-1 ?

ow...
i think not many people use the BCD . when i Google the two digit BCD , i haven't find any clue

Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: sleemanj on January 10, 2014, 06:30:37 am
yesterday my friend told me that he use BCD sequence like : 20-10-8-4-2-1 .

BCD is encoded with 4 bits typically, since there are only 10 decimal digits, that's all we need.

BCD is simply taking each digit of a decimal number, encoding to binary, and there you go:

0 = 0000
1 = 0001
2 = 0010
...
9 = 1001

That's all you need.  However some variations might further "characters", perhaps you want to add a decimal point, letters, some mathematical symbols, in which case another bit or two might be useful as an extension (if you need more than 6 extra characters anyway).

The Max7219 7-segment driver for example provides some extra characters in its BCD decoding, although it just fits them into the 6 slots after 1001 without requiring a 5th bit.

Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: sleemanj on January 10, 2014, 06:35:28 am

so the number will continuous to ..... 800-400-200-100-80-40-20-10-8-4-2-1 ?

Not really no.  Each digit is encoded as a bit sequence separately.

Eg, the number 1345 is encoded to the 4 binary sequences
0001
0011
0100
0101

(if those 4 digit binary numbers are packed into 2 bytes when sending or ... is not important for the discussion)

The wikipedia article is a good place for you: http://en.wikipedia.org/wiki/Binary-coded_decimal#Basics (http://en.wikipedia.org/wiki/Binary-coded_decimal#Basics)

Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: AlfBaz on January 10, 2014, 08:07:56 am
There was that other one i cant think of its name right now, that was similar to bcd but altered so that only one bit changed on each increment
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: arcom on January 10, 2014, 08:22:03 am
That's the Gray Code (http://en.wikipedia.org/wiki/Gray_code). Used a lot with rotary encoders and similar devices.
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: Dave on January 10, 2014, 08:33:55 am

so the number will continuous to ..... 800-400-200-100-80-40-20-10-8-4-2-1 ?

Not really no.  Each digit is encoded as a bit sequence separately.
Well, you would in term split them, but they kind of are together when you convert them.

This (http://people.ee.duke.edu/~dwyer/courses/ece52/Binary_to_BCD_Converter.pdf) is how you convert a binary number into a set of BCD digits. As you can see, the result at the bottom is a long sequence of bits which you then in term split into fours.
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: amyk on January 10, 2014, 10:40:31 am
Well in computing it can go either way, and it often will, even within the same system.

Intel CPUs as an example are "little endian" meaning that the bit with the lowest address is the least significant digit.  So, in your example, this would be 1-2-4-8.

ARM CPUs were big-endian (8-4-2-1) but as of version 3 they are now bi-endian, meaning that you can control the endianness via software configuration to suit your own needs.  Very handy.

When you design hardware that is implemented on an FPGA, it is very easy to swap endianness or to use little endian everywhere when you wanted big endian.

In short, both types are used all over the freaking place in digital systems.
Did you mean SPARC? ARM is little endian by default. SPARC started as big and became bi, ARM started as little and became bi.
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: woodchips on January 10, 2014, 06:31:16 pm
Aren't modern computer engineers spoilt today!

Wasn't it the TI 9900 that used bit 0 as the most significant bit. What a barmy idea that was, trying to concatenate words to make larger integers.

Mind you, that was better than the computers that had bit 15 as a parity bit, so concatenating had to include shifting and masking, ughh!
Title: Re: Why are BCD bits ordered 8-4-2-1 and not 1-2-4-8?
Post by: SeanB on January 10, 2014, 06:43:40 pm
Or processors that have a binary and a decimal mode, and if you leave it in decimal mode you get some really weird problems on things like conditional branches and carries.