0

If I have two bytes representing 117, 117 or 1110101 , 1110101 and I want to concatenate them (technically I know how) then which end attaches to which?

I understand they will be arranged in memory depending on endianess but overall, is there a standard way of concatenating bytes.

Lets say I want to concatenate these two into a 16 bit variable and they are arranged as above in little endian on a windows machine. 11101011110101 , i've just bolded on for clarity. Is that the way I would have to do it? OR, does the first byte always link to the least significant bits first? The reason I ask is that if concatenating bytes depends on endianess you are going to get two different results. I thought there may be some rules surrounding this.

3
Contributors
6
Replies
32
Views
3 Years
Discussion Span
Last Post by daino
1

Oh really?

Yes. The bit pattern will be different depending on the endianness of the architecture. There aren't any rules aside from being aware of the architecture and matching it, but a common guideline for portable code is to always use the same endianness for sharing bytes regardless of the architecture. The application then reorders bytes to match its own architecture.

For example, you'll notice that internet standard transmissions are big endian to maintain consistency.

0

Ok, so from what you are saying I gather that the order the data is received and read into my system, that is the way I read it. For example, I'm using Windows XP (Little Endian architecture), so memory is arranged like below:

Most Significant <-----> Least significant Most Significant <----> Least singificant bytes (there are two bytes here). So if I concatente bytes I do so in the order that memory is arranged in my system?

Is that correct?

Edited by daino: wording.

0

To put two bytes in a 16 bit word, multyply the first by 256 and add the second. In memory this would give first-second.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.