Question

I know there are mutliple questions relating to my question but i'm having difficulty understating how pack & unpack works.

for example using struct.pack("!B",14) gives me value of x0e basically this is a one-byte binary.

how can i create a four-byte binary? for example struct.pack("!B",104277) should generate 0x00019755 but i cannot get this code struct.pack("!B",104277) to output 0x00019755

Background details of my problem

I'm trying to create a "Type-4 High-resolution grayscale fingerprint image" record which is part of the NIST standard. The first value of Type-4 record is Length of the record (LEN) in this case its 104277 bits, but the standard specifies that the LEN should be represented as four-byte binary. The sample data I have contains this value 0x00019755 which already has been converted to four-byte binary thus complies with standard.

reference links:

Was it helpful?

Solution

As specified in §7.3.2.2. Format Characters of the Python manual, the format code for an unsigned 4-byte long is L.

struct.pack("!L", 104277)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top