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
8
votes
2 answers

Git pack filenames -- what is the digest?

Git stores individual objects in .git/objects/ab/cdefgh... where ab is the first byte of the SHA1 digest. However, pack files don't follow the same naming policy, and I can find no documentation on how it is named. Any insights?
romul
  • 149
  • 4
8
votes
1 answer

When/why should I use struct library in python to pack and unpack?

I cant understand when should I use pack and unpack functions in struct library in python? I also cant understand how to use them? After reading about it, what I understood is that they are used to convert data into binary. However when I run some…
shiva
  • 2,535
  • 2
  • 18
  • 32
8
votes
4 answers

Why does mixing types in Python struct.pack uses more space than needed?

I have just tried using struct.pack in Python for the first time, and I don't understand its behaviour when I am mixing types When I am trying to pack a single char and nothing else, it works as expected, i.e. struct.pack("b",1) gives '\x01'. But…
scozy
  • 2,511
  • 17
  • 34
8
votes
6 answers

jQuery Linking vs. Download?

Which way is better? To link to the jQuery Pack at http://ajax.googleapis.com. Or to download the appropriate file and link locally? Does it matter? Is there a chance the link may disappear? Or is there a chance the file online will be updated, and…
flipflopmedia
  • 517
  • 3
  • 6
  • 16
8
votes
3 answers

python pack() and grid() methods together

Im new to python so please forgive my Noob-ness. Im trying to create a status bar at the bottom of my app window, but it seems every time I use the pack() and grid() methods together in the same file, the main app window doesn't open. When I comment…
terence vaughn
  • 521
  • 2
  • 11
  • 23
7
votes
5 answers

Duplicate class kotlin classes kotlin version 1.3.70

Error while adding MoshiPack Library in Kotlin latest version 1.3.70 to gradle.build application Moshi pack implementation 'com.daveanthonythomas.moshipack:moshipack:1.0.1' Error Message Duplicate class kotlin.reflect.KClasses found in modules…
Mohamed Ali
  • 103
  • 1
  • 2
  • 9
7
votes
3 answers

struct pack return is too long

I'm trying to use the struct.pack function import struct values = (0, 44) s = struct.Struct('HI') b = s.pack(*values) print(b) print(str(len(b))) and it gives me this output: b'\x00\x00\x00\x00,\x00\x00\x00' 8 while the python docs say: Format -…
Dela
  • 146
  • 3
  • 15
7
votes
2 answers

packing and unpacking data structure with Perl6

on perl5 if someone want to parse binary file he has the pack/unpack utiltiy where he can convert binary structure to perl variables and vice verca , is there now a production equivlant for pack/unpack on perl6 ,as from the documentation i found…
smith
  • 3,232
  • 26
  • 55
7
votes
1 answer

Why is hex -> base64 so different from base64 -> hex using pack and unpack?

I got this code working, which converts from hex to base64, and vice versa. I got to_base64 from another SO question, and I wrote to_hex with some guesswork and trial and error. class String def to_base64 [[self].pack("H*")].pack("m0") …
Jonah
  • 15,806
  • 22
  • 87
  • 161
7
votes
2 answers

Reverting unpack('C*', "string")

I would like to know how I can reverse what this unpack function bellow performed. I think the pack function is able to reverse what unpack performed, however I'm not sure. First I have a simple string which after unpacking it I would have an array…
Fábio Antunes
  • 16,984
  • 18
  • 75
  • 96
6
votes
6 answers

Can you explain the bits I'm getting from unpack?

I'm relatively inexperienced with Perl, but my question concerns the unpack function when getting the bits for a numeric value. For example: my $bits = unpack("b*", 1); print $bits; This results in 10001100 being printed, which is 140 in decimal.…
Rob
  • 107
  • 1
  • 7
6
votes
1 answer

AVX2 byte gather with uint16 indices, into a __m256i

I am trying to pack a __m256i variable with 32 chars from an array and specified by indices. here is my code: char array[]; // different array every time. uint16_t offset[32]; // same offset reused many…
jianqiang
  • 123
  • 6
6
votes
3 answers

How do I compare packed values in Perl?

I want to use the pack() function in Perl to encode some data. Then I want to compare my packed structure to another packed structure. I want this compare to be on the byte values of this packed structure. According to the documentation, cmp uses…
PP.
  • 10,764
  • 7
  • 45
  • 59
6
votes
2 answers

Pack labels right next to entry box in tkinter python

I have a window that prompts users to enter the directory of their log files. However, my label seems to pack on top of my entrybox. Any idea on how to pack them side by side? labelText=StringVar() labelText.set("Enter directory of log…
user2633882
  • 1,551
  • 3
  • 11
  • 6
5
votes
1 answer

golang: pack a struct

Please consider this sample go code: package main //#include //#include //#pragma pack(push, 1) //struct Packed_Struct { // uint16_t A; // uint16_t B; // uint32_t C; // uint16_t D; //}; //#pragma pack(pop) // //struct…
struggling_learner
  • 1,214
  • 15
  • 29
1 2
3
45 46