2

if I have 4 multi-byte integers, A, B, C, D in a big endian system

and A-B = C-D

if they are in a little endian system, does the equality still hold?

Note: I want to get the difference between numbers which are received from network, so they are in network order or host order.

2
  • 3
    Yes. Of course. The mathematical operators will work on the multi-byte integers in the correct way for the platform. Commented Jun 12, 2013 at 14:19
  • You mean if the same bit-pattern is interpreted as little-endian integers? The equality need not hold then. Commented Jun 12, 2013 at 14:20

1 Answer 1

8

Endianness is only about the computer's representation of the numbers, not the values. The value is independent of endianness,1 so the equality holds.


1 Unless, of course, the bytes are incorrectly interpreted. This can happen, for example, when a big-endian system writes some bytes to the network and a little-endian system on the receiving side interprets them as little-endian.

Sign up to request clarification or add additional context in comments.

1 Comment

"Unless, of course, the bytes are incorrectly interpreted" -- This is why we have ntohl() and htonl() functions.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.