Exam GPYC All QuestionsBrowse all questions from this exam
Question 21

A log file is stored in variable `a`. The file has the following format for each log entry, in order, stored in big endian:

Field 1: 2-byte integer -

Field 2: 2-byte integer -

Field 3: 4-byte integer -

Which of the following would unpack a line from the log file into the proper fields?

    Correct Answer: A

    To unpack a line from the log file described, we need to consider the specified format. The file has two 2-byte integers and one 4-byte integer, and it is stored in big endian. The correct format string for this would be '>HHI'. However, since the 4-byte integer can also be represented as a 4-byte string, '>HH4s' is appropriate. The '>' symbol indicates big endian, 'H' stands for 2-byte integers, and '4s' stands for a 4-byte string.

Discussion
mrmrmeOption: C

struct.unpack(r'!HHI',a) = ! is Big Endian, H is 2 bytes, I is 4 bytes, a is the variable

mrmrme

the 4s indicates a string of 4 bytes.