What does byte execution mean?

There are many places discussing how to make different types of bytes, but I couldn't easily find a place that explains the concept and some typical examples of how the need for bytes arises.

So here's the question: what is byteswapping and why / when do I need to do it?

If examples are a good way to explain, I would be glad if they were in standard C ++. Book references are welcome, preferably for Lippman or Pratas C ++ primers as those I have available.

+3


source to share


2 answers


If I understand your question correctly, you are talking about converting big endian

to little endian

and from.

This is because some microprocessors use a format little endian

to access memory, while others use a big endian

.

Streams on the Internet, for example, big endian

while your Intel processor is formatting little endian

.



Hence, to transfer from network to CPU or CPU to network, we need a conversion mechanism called batwapping.

To perform this action, the OS provides the functions ntohl()

and htonl()

.

+3


source


As mentioned in the comments, batwapping is the process of changing endianess values from one to another. Let's say you have a value in your memory (lowest address on the left):

DE AD BE EF   <- big endian

      

This figure is 4 bytes - in hexadecimal notation, two digits - one byte.



If we assume that the above value is encoded in large endian, then this would mean that the least significant bit of order if the very first byte in memory is here DE

. Intel x86 processor architecture runs with a small number of characters, which means that the memory will have the same value as above:

FE BE AD DE   <- little endian

      

These two values ​​represent the same meaning, but have different endianess.

+1


source







All Articles