As I understand it, you are trying to get a unique BIG_ENDIAN (or LITTLE_ENDIAN) number without knowing what your current host agreement is. It should be possible.
To my best understanding, the "network byte order" convention is always BIG_ENDIAN. So you can call htonx (), then you know that it is BIG_ENDIAN. Then, if you want LITTLE_ENDIAN, you can manually transfer the bytes into your own code. The result should be your own toBigEndian () or toLittleEndian () functions.
The second part of the question does not allow one and the same, since it is completely a matter of convention. Let's say that this number is equal to two bytes - almost every combination of 16-bit values ββis the actual number 1 of the complement, as well as the real number of the 2nd complement. The βcorrectβ value depends entirely on the interpretation that was imposed on it by the code that wrote this value.
source share