Library C function to convert binary byte array to integer with various conversions

Is there a set of C library functions (or somewhere not library functions) that allow you to convert byte array data to integers with various conversions (big data, low-intensity data, one addition to a subscription, two additions to signing, etc.), taking into account the intrinsic nature of the machine?

Thanks!

+4
source share
2 answers

This is close, although I don't think it will handle one add-on compared to two add-ons. You could add this. http://code.google.com/p/protobuf-c/

+1
source

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.

0
source

All Articles