49.4k views
5 votes
Consider sending a message containing a string of integers over the Internet. What problems may occur if the sending and receiving machines have different "endian-ness"? How might you solve these problems? 5.2 What is the largest positive number in 32-bit two's complement arithmetic? What is the smallest (largest magnitude) negative number? Why are these numbers not the additive inverse of each other? 5.3 (a) Express the decimal number 1234 in hexadecimal. (b) Express the unsigned hexadecimal number 0×2ae in decimal. 5.7 Exercises C−101 (c) Interpret the hexadecimal bit pattern 0xffd9 as a 16-bit 2's complement number. What is its decimal value? (d) Suppose that n is a negative integer represented as a k-bit 2 's complement bit pattern. If we reinterpret this bit pattern as an unsigned number, what is its numeric value as a function of n and k ? 5.4 What will the following C code print on a little-endian machine like the x86 ? What will it print on a big-endian machine? unsigned short n=0×1234;//16 bits unsigned char ∗p= (unsigned char ∗) la; 5.5 (a) Suppose we have a machine with hardware support for 8-bit integers. What is the decimal value of 11011001 2 , interpreted as ansigned quantity? As a signed, two's complement quantify? What is its two's complement additive inverse? (b) What is the 8-bit binary sum of 11011001 2and 100100012 ? Does this sum result in overflow if we interpret the addends as unsigned numbers? As signed two's complement numbers? 5.6 In Section C-5.2.1 we observed that overflow occurs in two's complement addition when we add two non-negative numbers and obtain an apparently negative result, or add two negative numbers and obtain an apparently nonnegative result. Prove that it is equivalent to say that a two's complement addition operation overflows if and only if the carry into most significant place differs from the carry out of most significant place. (This trivial check is the one typically performed in hardware.)

User Momoja
by
8.2k points

1 Answer

4 votes

Final answer:

Different 'endian-ness' between sending and receiving machines can lead to problems in interpreting integer values when sending messages over the Internet. This can be solved by using a consistent byte ordering protocol or converting the byte ordering explicitly. The largest positive number in 32-bit two's complement arithmetic is 2147483647, while the smallest negative number is -2147483648.

Step-by-step explanation:

When sending a message containing a string of integers over the Internet, one potential problem that may occur is if the sending and receiving machines have different 'endian-ness', which refers to the order in which bytes are stored in memory. This can lead to incorrect interpretation of the integer values.

To solve this problem, several approaches can be taken. One option is to use a well-defined byte ordering protocol, such as network byte order (big-endian), to ensure consistency between machines. Another option is to explicitly convert the byte ordering of the integers before sending or after receiving them.

The largest positive number in 32-bit two's complement arithmetic is 2^31 - 1, which is equal to 2147483647. The smallest (largest magnitude) negative number is -2^31, which is equal to -2147483648. These numbers are not the additive inverse of each other because of the way two's complement representation works. In two's complement, negative numbers are represented by taking the bitwise complement of the positive number and adding 1.

User JellyRaptor
by
6.9k points