An integer has no idea in it. You cannot determine if it is just looking at bytes, big or small. You just need to know: for example, if your 8-bit processor is a little oriented, and you get a message that is known to be a big endian (because, for example, the fieldbus system defines a large end), you need to convert values ββover 8 bits . You will need either hard code or the definition of some definition in the system by which the bytes will be replaced.
Note that replacing bytes is easy. You may also need to swap bits in bit fields, since the order of the bits in the bit fields is compiler specific. Again, you basically should know this at build time.
source share