C Multiple Choice Questions & Answers (MCQs) on “Endianness”.
1. A machine in which the least significant byte is stored in the smallest address is __________
a) Big endian machine
b) Bi-endian machine
c) Binary bit machine
d) Little endian machine
Answer: d
Clarification: In little endian machines, last byte of binary representation (least significant byte) of a multi byte data type is stored first, whereas in big endian method, the first byte of binary representation of a multi byte data type is stored first.
2. If the output of the following C code is “Big endian”, then what will be the value of *a is?
#includeint main() { unsigned int i = 1; char *a = (char*)&i; if (*a) printf("Little endian"); else printf("Big endian"); getchar(); return 0; }
a) -1
b) 0
c) 1
d) 2
Answer: b
Clarification: In the code shown above, a character pointer ‘a’ points to an integer ‘i’. Since the size of the character is 1 byte, when the character pointer is de-referenced, it contains 1 integer byte. If the machine is a little endian machine then the value of *a will be 1, since the last byte is stored first. If the machine is big endian, the value of *a will be 0.
3. It is possible for a processor to support both little and big endian methods.
a) True
b) False
Answer: a
Clarification: It is possible for a processor to support both little and big endian methods. Such machines are known as bi-endian machines.
4. The standard byte order for networks is ____________
a) Bit-Binary
b) Little endian
c) Big endian
d) Bi-endian
Answer: c
Clarification: The standard byte order (network byte order) for networks is big endian. Before transferring data on a network, data is converted to big endian.
5. Which of the following is not an example of big endian machines?
a) Power PC
b) Motorola 68K
c) SPARC processors
d) ARM processors
Answer: d
Clarification: ARM processor is an example of little endian machine. Current generation ARM processor is an example of bi-endian machine. Power PC, Motorola 68K and SPARC are examples of big endian mahines.
6. Suppose we transfer a file written on a little endian machine to a big endian machine and there is no transformation from little endian to big endian, then what happens?
a) The big endian machine throws an error when it receives the file
b) The big endian machine reads the file in the reverse order
c) The big endian machine does not read the file
d) The big endian machine reads the file in the normal order
Answer: b
Clarification: If there is no transformation from little endian to big endian on transfer of a file from a little endian machine to a big endian machine, the big endian machine reads the file in reverse order.
7. File formats which have _________ as a basic unit are independent of endianness.
a) 1 byte
b) 2 bytes
c) 3 bytes
d) 4 bytes
Answer: a
Clarification: File formats which have 1 byte as the basic unit are not endianness dependent. Eg: ASCII files. Other file formats have fixed endianness formats.
8. If the code shown below is executed on a little endian machine, then what will be the output of the following C code?
#includemain() { int y=1; printf("%d", (*(char*)&y)); }
a) 1
b) 1000
c) 9999
d) 0
Answer: a
Clarification: The output of the above code will be one when it is run on a little endian machine. This is because a little endian machine stores the least significant byte in the smallest address.
9. If the data “ABCD” is to be stored in a little endian machine, it will be stored as _________
a) ABCD
b) DCBA
c) CDAB
d) BCDA
Answer: b
Clarification: In a little endian machine, the least significant byte (right most) is stored in the smallest address. Hence the data “ABCD” will be stored in the form of “DCBA”.
10. The sequential order used to interpret a range of bytes in the memory of a computer is known as _________
a) Ordering
b) Sequencing
c) Endianness
d) Byte prediction
Answer: c
Clarification: Endianness is the sequential order used to interpret a range of bytes in the memory of a system.