Why are binary numbers almost always grouped in 4 bits?

4.1k views Asked by At

I'm learning ARM so going back to basics with binary/hex arithmetic and it got me thinking about how binary numbers are usually presented in groups of 4, e.g.

1111 1110 1101 1100

Is there a particular reason why it's done this way? Seeing as we normally describe memory in terms of bits/bytes/megabytes etc I'd have thought they'd be better grouped by 8?

3

There are 3 answers

0
Mohsen Alyafei On

One reason is that it becomes easy for representation and conversion into Hexadecimal. One Hexadecimal Digit consists of (represents) 4 bits.

enter image description here

1
zx485 On

The grouping can often be changed from 4bit(a nibble) to 8bit(a byte) or 16bit(a word) or 32-bit(a dword).
The reason why values are often grouped in 4bit sections is that 4bit can be represented as a hexadecimal number:

So

1111 1110 1101 1100    can be represented as
F    E    D    C       in hexadecimal

In a hexdump these 2 bytes could also be represented as FEDC in big-endian or CDEF in little-endian. In a BYTE based system, an 8bit value consists of two 4bit values called nibbles. The above value can be separated like this FE DC or CD EF.

0
old_timer On

So octal was pretty common, possibly for multiple reasons, understand this is a primarily opinion based question so there is no right answer (well closest is "because everyone else does and that's how I learned").

Base 10, decimal, we know, we have 10 fingers, 10 toes, we have created 10 symbols we recognize for those 10 numbers.

Base two is cumbersome, we tend to re-use the decimal numbers 0 and 1 but base two so that's it two symbols.

Base 8, octal, is one natural way to represent binary as it doesn't take as many digits, any power of two will work. base 4 doesn't get us much but base 8 starts to. And companies like DEC which were pretty dominant back on the day used octal and so folks on those machines in that period had to speak octal. Octal also has the advantage over hex that it only needs 8 symbols and we can, like base 2, repurpose decimal digits 0-7. Half the number of things to memorize to convert between binary and octal in your head.

But octal is a strange power of 2 three bits. Four is also a power of two, for possibly various reasons the size of the byte (even in DEC days) gravitated to 8 bits (a byte has been a wide range of sizes, wasn't always 8 and possibly still isn't in some legacy systems), maybe 128 was not big enough and 512 was too big or because a power of two power of two made more sense. So naturally hex falls out of this, no doubt computer folks were getting used to removing themselves from base 10 and being able to think in other bases, and now stealing from the alphabet to fill in the remaining 6 symbols, memorizing a larger table, etc. has become the norm. You still see octal, it is still supported in C and other languages, the pdp11 backend to the gnu tools just feels wrong in hex, but it is what it is, they could easily make the disassembler, etc output octal or have octal be the default, but hex seems to be here to stay its a good compromise, greatly easier to use than binary, wee bit easier than octal, way easier than octal for systems with 8, 16, 32, 64 bit items (registers, buses, etc) (compared to 9, 18, 36 bit items as some processors had/have).

Again no right answer to this as, its not really possible to confirm. But as with other things, no doubt, at the right time in history when the right thing was created, for example someone decided to make some ram chips to sell, and either they made a selection of choices (4 bit, 8 bit, 9 bit, 16 bit 18 bit) or they sat down in a room and decided we are only going after one product line and this is it, and then if that is the only ram you can buy at a great expense and it is 8 bit then your 9 bit processor means your customer has to pay a lot more money for ram as they would maybe need two chips and do an 8+1 thing or a 4+5 thing or whatever. And/or there were these products and particular ones sold better.

Why are there still x86 processors out there when far superior ones can be built, cheaper, run faster, less power, etc. Not because x86 is better but because of multiple other factors including, the devil you know vs the devil you don't. Why does windows still exist when there are really good if not superior alternatives? Why are macs so grossly overpriced for what you get? Not because it is right, not because of technology, but because of a combination of factors including emotion.

If you were lucky enough to work with the folks from the octal days and see how they struggle with hex, then yourself being brought up with hex and for most folks struggle with octal if they even try, that is a big part of it too. It is what you were taught it is what you know. Your teacher will say it is what they were taught and what they know, perhaps a couple-three generations back might land in the its what we could afford, and we learned the thing we bought and the people that sold it did it this way.

I think it is clear that binary is not efficient nor easy and error prone. Both octal and hex work fine, base 32 would be cumbersome as would base 64, so base 8 or base 16 are in the sweet spot and arguably base 16 won.

Note that because bytes are typically 8 bits we do very often group things in bytes, by using two hex digits. memorizing 256 symbols, after we somehow create 256 symbols would be a deal breaker, you wouldn't get any adoption.