Questions tagged [pack]

A function in several scripting languages for packing data, creating a sequence of specifically ordered and aligned bytes, into a binary structure. The opposite of the `unpack` function. This tag should be used with a programming language tag as well. While also used as a directive or pragma in some compilers to cause the compiler to ignore standard variable alignment for data aggregates (i.e. struct), do not use this tag for posts on that subject.

The pack function combines several high-level variables into a single low-level binary representation that usually matches the machine-level representation that you would see in a C struct. The inverse operation is .

Most versions of pack and unpack functions use a format or template that specifies the byte by byte layout of the data being put into or copied out of the memory area containing the binary representation.

Documentation:

682 questions
4
votes
2 answers

auto-repeat flag in a pack format string

In php, unpack() has the "*" flag which means "repeat this format until the end of input". For example, this prints 97, 98, 99 $str = "abc"; $b = unpack("c*", $str); print_r($b); Is there something like this in python? Of course, I can do str =…
georg
  • 211,518
  • 52
  • 313
  • 390
4
votes
4 answers

Pad a packed struct in C for 32-bit alignment

I have a struct defined that is used for messages sent across two different interfaces. One of them requires 32-bit alignment, but I need to minimize the space they take. Essentially I'm trying to byte-pack the structs, i.e. #pragma pack(1) but…
Alex
  • 827
  • 8
  • 18
4
votes
2 answers

C++ template parameter pack expansion of alias

So, my motivation here is to determine whether the same named type declaration within several classes are the same type. In this example, I'm looking to see that all of Foo, Bar, and Baz have an internal type Q. #include template…
CodeWeaver
  • 41
  • 3
4
votes
1 answer

php5 pack is broken on x84_64 env

pack('H*', dechex(12345678900)) /* on 32bit */ != pack('H*', dechex(12345678900)) /* on 64bit */ why ?
freddiefujiwara
  • 57,041
  • 28
  • 76
  • 106
4
votes
1 answer

How do I pack 128- or 256-bit numbers

Is it possible to pack 128- or 256-bit numbers (AES keys/ivs generated with Crypt::Random::makerandom) using the perl built-in pack? If yes, what should my template X in pack('X', ($256_bit_number)); be? Thank you.
Gurunandan Bhat
  • 3,544
  • 3
  • 31
  • 43
4
votes
1 answer

tkinter buttons not displaying

When I execute the script the background image works as it should, it will match the size of the window, however, I cannot get the buttons to show (they have no functionality yet). I am fairly new to python so I'm not sure if I am using buttons as…
EcSync
  • 842
  • 1
  • 6
  • 20
4
votes
1 answer

dotnet pack: version format

I'm packing my nuget package using dotnet pack command and before update my projects to dotnet core 1.1.2 and vs2017 I was able to put version of package with 4 numbers according our internal conventions (YEAR.RELEASE.PATCH.BUILD -…
Dumitru
  • 833
  • 3
  • 12
  • 26
4
votes
1 answer

Problem with sending an array using 'pack' function in perl

I am using pack function to send contents of a list to a socket. Code is given below. $message_array = pack ("(A*)*", @ul_dcch_message); The list contents are @ul_dcch_message = (101101012411011, "emergency", 25, "simple"); This piece of code…
Senthil kumar
  • 965
  • 3
  • 16
  • 33
4
votes
1 answer

Nuget pack how to set/change dependency version via command line

The problem how to dynamically change dependency version in the nuspec file during nuget pack MyPacked.Name 1.1.1 Pawel Cioch Pawel…
Pawel Cioch
  • 2,895
  • 1
  • 30
  • 29
4
votes
1 answer

struct.pack(!i, 10) result is "00 00 00 0d 0a" on Windows

I found an odd problem with Python's struct.pack("!i", 10) on a Windows system. I get the buffer and save it in to a file, but the result is 00 00 00 0d 0a where on Mac OSX, the result is 00 00 00 0a What does the 0d mean? When I pass 11 instead…
oneRain
  • 49
  • 1
4
votes
4 answers

Pack / unpack a 64-bit int on 64-bit architecture in PHP

Why do I get the following output on an x64 architecture? $ php -r 'echo pow(2, 33) . "\n";print_r(unpack("Ivalue", pack("I", pow(2, 33))));' 8589934592 Array ( [value] => 0 ) It seems as though it can handle signed 64-bit ints, but it can't…
sberry
  • 128,281
  • 18
  • 138
  • 165
4
votes
0 answers

JFXPanel Dynamic Sizing

In the process of converting from Swing to FX. We currently have JFXPanels within JInternalFrames. When initially displaying a new screen, everything is fine because we are first setting the scene and then calling the pack() method on the…
Tommo
  • 977
  • 14
  • 35
4
votes
6 answers

How to print a variable in reversed byte order?

I'm trying to convert the variable $num into its reverse byte order and print it out: my $num = 0x5514ddb7; my $s = pack('I!',$num); print "$s\n"; It's printing as some non-printable characters and in a hex editor it looks right, but how can I get…
jth
  • 43
  • 3
4
votes
1 answer

Pack/unpack array of binary data

I have an array of unsigned integers (32 bits) that I want to pack into a binary stream: my @n = (4,8,15,16,23,42); my $foo = join('', map(pack('I', $_), @n)); # Ugly, isn't? $foo should contains this binary stream (depending on the…
nowox
  • 25,978
  • 39
  • 143
  • 293
4
votes
1 answer

Can you pack multiple Tkinter widgets at a time rather than packing them individually?

You create an initial root window and then multiple widgets (such as Labels, Buttons, Events). You have to pack each one of them and can do it in several ways that I'm aware of. Button(root, text="Button1", command=something).pack() or btn1 =…