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.

Recommended Answers

All 6 Replies

You have to be aware of the computer archtecture you are working with.

Oh really?

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.

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?

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.

So is my assumption correct??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.