GPYC Exam QuestionsBrowse all questions from this exam

GPYC Exam - Question 26


Review the following code:

What is the output?

Show Answer
Correct Answer: B

The code uses the struct module to unpack a binary string. The given string '\x01\x00' represents a 2-byte value. The '<H' format string specifies little-endian order with an unsigned short (2 bytes). In little-endian byte order, the least significant byte comes first. Therefore, '\x01\x00' is read as 0x0001, which is equal to the integer value 1. The unpack function returns a tuple with one element, which is (1,).

Discussion

2 comments
Sign in to comment
howefo8913Option: B
May 23, 2021

>>> a = "\x01\x00" >>> struct.unpack("<H",a) (1,) >>>

a29dc2cOption: B
Feb 7, 2024

that answer is B