2

I have a hard time understanding the use of MSB (Most significant bit) vs. LSB (Least significant bit) and why they're used at all. It is my understanding that it has to do with Endianness, but I cannot get my head around it.

Basically: If I read a specification on X and they specify that the data needs to be read LSB or MSB - ok I can do that - but why am I doing it.

Why don't we just send all data MSB?

Benny Mose
  • 147
  • 1
  • 1
  • 6
  • ...see also: [Is a 'least significant bit' used anywhere practically today?](http://programmers.stackexchange.com/questions/275113/is-a-least-significant-bit-used-anywhere-practically-today) – gnat Aug 13 '15 at 20:51
  • Thank you guys, for both links. I'll read them straight away :) – Benny Mose Aug 13 '15 at 20:53
  • 2
    Short answer: they're good for provoking endian wars. –  Aug 13 '15 at 20:59
  • @Michael If you could post a link to the specification which you are reading, it may make it easier for us to explain. – Nick Alexeev Aug 13 '15 at 21:02
  • @NickAlexeev I don't really have it online, but here's a section of the PDF: http://cl.ly/image/2X0I2Q3a2f1O/Screen%20Shot%202015-08-13%20at%2023.22.16.png "Within one byte, the least significant bit (LSB) is first in the se- quence and the most significant bit (MSB) is last." – Benny Mose Aug 13 '15 at 21:23
  • 2
    Sigh. A few shared keywords does not a duplicate make. – Karl Bielefeldt Aug 13 '15 at 22:03
  • 1
    @KarlBielefeldt - A few short sentences do not a good question make. I agree that there's potential behind this question, but it's not clear what the OP doesn't understand. Given the multitude of information already available regarding MSB, LSB, and {big | little} endian, the community is left with a guessing game as to the actual question. The [OP's comment](http://programmers.stackexchange.com/questions/293663/what-is-the-use-of-msb-and-lsb#comment608364_293663) is / was highly indicative of the suggested duplicate answering their question. –  Aug 14 '15 at 15:04
  • @GlenH7 You're obviously not aware of how hard to it is, for some, to ask/craft a question to SO's "standards" (which change from universe to universe) about something you don't really know much about/want information about. The time and effort people have taken to answer mine are overwhelming in this question and answer everything I wanted to know about MSB/LSB and all the W's (how/what/why). – Benny Mose Aug 14 '15 at 19:59
  • @GlenH7 Everyone is welcome to edit the original question in order to help out, making it a "real and non-guessing question" based on what has been provided by everyone here. If I could ask the question to such an extent, I would be able to Google my way to all the answers, which I wasn't able to in this case. There's too much indirect information east and west. I don't think it should be left to rot as everyone who answered has provided such great answers to me, which is much appreciated. Hell, I've even bookmarked the question so I can return to it. So thanks to everyone here <3 – Benny Mose Aug 14 '15 at 20:01

4 Answers4

12

Endianness for binary (base 2) is no different than endianness for any other base.

Without a specification telling you which side the most significant and least significant decimals were, you wouldn't know whether

1234

is one-thousand-two-hundred-and-thirty-four or four-thousand-three-hundred-and-twenty-one.

Note for additional curiosity that "twenty-one" is MSD whereas "nineteen" is LSD, so it's certainly not that universally obvious even within the same community which one is the right one.

For dates, there are three different conventions (using Alan Turing's birthday as example):

  • least significant component first (e.g. in Germany): 23.06.12
  • most significant component first (e.g. ISO): 12-06-23
  • complete and utter confusion (US): 06/23/12

Again, you have to pick some order, and you have to communicate which order you picked, and there is no obviously "right" order. (I would argue though, that the US date format is obviously wrong :-D .)

Jörg W Mittag
  • 101,921
  • 24
  • 218
  • 318
  • Well explained, thank you. Together with your other comment, I drew the same conclusion in regards to why we don't just send data the same way (MSB or LSB) - why don't we all speak english? That must be the same answer in the end. I'm looking for an answer to "why was LSB created then..", but I could keep asking myself these things I guess - why was the French language "created", and keep going until the end of time :). Thanks again! Helps a lot. – Benny Mose Aug 13 '15 at 21:51
  • 1
    LSB wasn't "created". It just exists. It is an equally valid and equally sensible way to send data. Left-side driving wasn't "created", right-to-left and top-to-bottom writing systems weren't "created". It is completely and utterly irrelevant which side of the road you drive on, as long as you and the person coming towards you agree. There is absolutely no reason for one or the other. It is irrelevant whether you write left-to-right or right-to-left or top-to-bottom, there are no inherent advantages or disadvantages. – Jörg W Mittag Aug 13 '15 at 22:02
  • @JörgWMittag great answer! But to play Devil's advocate, there is arguably the disadvantage for a right-handed person that they would be more likely to smudge if they write right-to-left with a quill and ink, no? – Carson63000 Aug 14 '15 at 00:02
  • @Carson63000: I thought about including that. (I'm a leftie, thus very much aware of the issue!) That would then be an obvious advantage for top-to-bottom, since that works equally well for both lefties and righties. – Jörg W Mittag Aug 14 '15 at 01:04
  • Thankfully, the ISO 8601 chose a sane date format: YYYY-MM-DD :) – Petrus Theron Mar 11 '19 at 20:11
1

When a byte is serialized into a stream of bits and transmitted serially, it becomes important to know whether it's transmitted LSbit-first or MSbit-first. The transmitter can send the bits in either order, and the contract whether it's LSbit-first or MSbit-first is established in the spec (or datasheet). For example, the receiver receives this:

time: 01234567
bit:  01000000

If the transmitter was sending LSbit-first, then the value is 0x02. If the transmitter was sending MSbit-first, then the value is 0x40. The receive has to know which one it is.

Nick Alexeev
  • 2,484
  • 2
  • 17
  • 24
  • That makes sense, and I understand that - but what I'm confused about is (and that might be a long subject), why the two different types of contracts? Why do we not always send data MSB. Is it based on the type of "machine" that is sending? – Benny Mose Aug 13 '15 at 21:22
  • 2
    Because you can do it both ways, and there is no overwhelming reason to do it one way or the other. Both have their advantages and disadvantages. Historically, computer manufacturers weighed the advantages and disadvantages differently, and arrived at different trade-offs. Note that this is also true in the English language ("nineteen" is least-significant-decimal first, "twenty-one" is most-significant-decimal first), or in date formats (ISO is year-month-day, i.e. most-significant-component first, German is day.month.year, i.e. least-significant-component first and US is month/day/year, … – Jörg W Mittag Aug 13 '15 at 21:47
  • … which makes no sense at all). – Jörg W Mittag Aug 13 '15 at 21:48
1

Bit order and byte order are two separate things, but they may affect your preferences. Say you have a little-endian machine, and you want to transmit a 32-bit number. Also transmitting the bits LSB-first means overall bit order for the entire int (with lsb numbered 0) is:

0 1 2 3 4 5 6 7 8 9 10 11 12 ... 31

If you transmitted MSB-first, the overall bit order for the entire int would be:

7 6 5 4 3 2 1 0 15 14 13 11 ... 24

Looking at this signal on an oscilloscope just got more difficult, and designing shift registers in hardware just got a little more tricky.

The reverse occurs for big-endian machines. So endianness doesn't dictate bit order, but it sure does make one bit order easier to work with.

As far as preferring one endianness over another, it's more than picking one at random. Big endian is easier to understand conceptually, but little endian means you don't have to offset the address in order to treat a byte as a word.

Karl Bielefeldt
  • 146,727
  • 38
  • 279
  • 479
1

MSB and LSB can be thought of in terms of numeric properties of bit sequences. For example, during addition, the carries flow from the addition of two LSB's toward the next higher bit. The LSB itself receives no carry because it starts the addition; whereas all the other bits get a carry from the next least significant bit position. Overflow is when a carry (of value 1) happens from the MSB, because there are no more bits (in the byte or word size) left to carry over to. The MSB is also considered the sign bit for signed data types: if the MSB is 1 the value is negative, if 0 the value is positive (or zero).

Endianess is a matter of the storage (or transmission) order for bits within a byte and also more significantly (as it turns out) for the order of bytes within a word or long word. These differences can be seen when data is moved from one system to another. Fortunately bit order within a byte is standardized on hard drives and networks, so we don't have to worry about bit endianess. However, byte order within a word is different for some processors than others, and bytes become swapped when changing architectures; as this causes problems it requires mitigation (e.g. software has to handle it). Little endian stores least significant bytes first followed by more significant bytes in higher storage or packet address order, whereas big endian is the opposite.

Erik Eidt
  • 33,282
  • 5
  • 57
  • 91