GIAC Python Coder (GPYC) — Question 9

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?

Answer options

Correct answer: A

Explanation

The correct answer, A, uses the format '>HH4s', which matches the big endian requirement for two 2-byte integers followed by a 4-byte integer. Option B incorrectly specifies a little endian format and has too many string format specifiers. Option C is correct in endianess but incorrectly specifies three 2-byte integers instead of the required fields, while option D mixes byte and string formats incorrectly.