Questions tagged [struct.pack]

34 questions
1
vote
1 answer

Python -0.000000e+00 struct pack return wrong value

Hi I have problem with parsing -0.000000e+00 on linux( on windows is working). struct.pack( "d", -0.000000e+00 ) On linux struct.pack change -0.000000e+00 to 0.000000e+00. When i print value before pack is correct but result of struct.pack is like…
Luffy
  • 677
  • 1
  • 6
  • 19
0
votes
0 answers
0
votes
1 answer

How to send an IPv6 address with the 'struct' library in python

I'm asking for your help because I've been stuck with the same problem for 3 days. If I have : Value1 = 0, Value2 = 3.10 and IPv6 = '2001::1' I would like to pack all 3 values with this command: package = struct.pack(*format*, value1, value2,…
Wyrox51
  • 3
  • 1
0
votes
1 answer

Getting TypeError: object of type 'int' has no len() when using struct.pack(), but only in a class

I'm getting this 'TypeError: object of type 'int' has no len()' for a data conversion function that I am trying to integrating into a class. Outside of the class it works with no errors, put it into the class, or try to access it inside of the…
0
votes
1 answer

struct.pack shows shifted data

I am trying to use struct.pack to pack a hash disgest, but not getting the expected result. This is how I am packing the data: hash = hashlib.sha256(input).digest() print('hash = ', hash.hex()) packed = struct.pack('!32p', hash) print('packed = ',…
user9241855
  • 25
  • 1
  • 7
0
votes
1 answer

Python - Writing a specific amount of bytes in a Binary file

Sorry if this is a duplicate question, I'm fairly new to python and don't fully know the nomenclature so its hard to search for solutions. I'm trying to write a code that outputs a binary file in specific integer formats, ie a section in 8 bit,…
0
votes
2 answers

struct.pack() returns a blank value

When I try to do the following: struct.pack("B",32) The 32 is a int type. I am expecting "\x20", but I get the following (blank): " " I need this as a byte using struct() because I want to put it in a bytearray(), to look like…
NMSilva
  • 3
  • 2
0
votes
1 answer

unpacking pythons struct.pack in another language

I want to "unpack" OR de-serialize the formatted data that is outputed from python's struct.pack() function. The data is sent over the network to another platform that uses Java only. The Python function that sends data over the network, uses this…
cyber101
  • 2,822
  • 14
  • 50
  • 93
0
votes
2 answers

Python struct.pack is not consistent

I am using struct.pack to return me a bytes object. However, it is inconsistent. print(struct.pack('BbbB', 0x1B, -2, 1, 0)) #returns b'\x1b\xfe\x01\x00' GOOD print(struct.pack('BbbB', 0x0F, -2, 1, 0)) #returns b'\x0f\xfe\x01\x00'…
Gabriele
  • 737
  • 2
  • 8
  • 20
0
votes
0 answers

Meaning of * character in a struct.pack line?

Can anyone tell me what the * character is doing in this line of python code? struct.pack(">%df" % numframes, *[frame/fps for frame in xrange(numframes)]) I've look through the documentation but I can't find that character on it's own. Thanks!
Berkyjay
  • 158
  • 1
  • 1
  • 10
0
votes
1 answer

Struct. pack error in python 3 - struct.error: argument for 's' must be a bytes object

I know this question has been asked before, and some of the suggestions seem to be about needing a b to make the string a byte literal. However, im passing hex code to the function as 0x414243 to save it as ABC. def _pack(_data, size): …
user1003967
  • 137
  • 2
  • 11
0
votes
1 answer

Python struct.unpack - converting binary string literals to ascii text writing to file

We use struct.unpack to read a binary file created out of a dump of all the C structures fields and their values (integers and strings). The unpacked tuples are then used to create an intermediate dictionary representation of the fields and their…
Rohit
  • 1
  • 3
0
votes
1 answer

Bytestring to normal chars. python's struct.pack

I've this python code that generates bytes import threading import socket import struct import time from datetime import datetime import random TICKERS = ["AAPL", "GOOG", "MSFT", "SPY"] timestamp = datetime.utcnow() ticker =…
Alexander Kondaurov
  • 3,677
  • 5
  • 42
  • 64
0
votes
1 answer

How to create long string of bytes in big-endian format

I'm trying to create a 16 bytes string on the wire in Big-Endian format. As you can see I'm ending-up with Little-Endian; where prepended 0's are at the end. >>> import struct >>> auth = "{0:<16}".format(1437722681) >>> authenticator =…
user5156958
0
votes
1 answer

Python 3 struct.pack not formatting hex string correctly

#res\file_1.png- file_1 file_1_size_bytes = len(file_1_read) print (("file_1.png is"),(file_1_size_bytes),("bytes.")) struct.pack( 'i', file_1_size_bytes) file_1_size_bytes_hex = binascii.hexlify(struct.pack( '>i',…
Death_Dealer
  • 325
  • 4
  • 17