pack

What is the realtime use of PHP pack and unpack function?

最后都变了- 提交于 2019-12-23 04:07:10
问题 I saw some file generation codes which uses the pack function. echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0); What this is doing exactly? s signed short (always 16 bit, machine byte order) I dont know why i am not able to understand this in realtime. Am not asking a theoretical answer When i execute the php , file got generated with some stange characters which is not identified by ms excel. I just want to know the use of pack(), where to use and how to use? 回答1: pack is generally used

How to pack a UUID into a struct in Python?

南笙酒味 提交于 2019-12-22 06:06:06
问题 I have a UUID that I was thinking of packing into a struct using UUID.int, which turns it into a 128-bit integer. But none of the struct format characters are large enough to store it, how to go about doing this? Sample code: s = struct.Struct('L') unique_id = uuid.uuid4() tuple = (unique_id.int) packed = s.pack(*tuple) The problem is, struct format 'L' is only 4 bytes...I need to store 16. Storing it as a 32-char string is a bit much. 回答1: It is a 128-bit integer, what would you expect it to

Algorithm to calculate the positions of random circles so they don't overlap

别来无恙 提交于 2019-12-21 05:22:09
问题 I have the following problem. I have a large region populated with a random number of circles of different sizes. If a new circle of random radius is inserted in a random location, I'd like to find a nearby position for it so it doesn't overlap with any of the others. It's optimal if the circles stay close. The number of circles and their size are limited, but random. The region will be quite large, (2500x2500, maybe) so an array of pixels as proposed here is out of the question. A person who

Perl's pack function equivalent in Java

那年仲夏 提交于 2019-12-20 03:34:07
问题 I have some Perl code that I need to transpose in Java. In this code I have to deal with Perl's pack. Is there an equivalent function in Java? The Perl code looks something like this: $somevar = pack "H*", $vartopack; 回答1: Perl's pack / unpack functions are a highly versatile conversion utility with its own format syntax (used in H* here, which makes it take an arbitrarily long hex string as input) of which there is no direct equivalent in the Java world. However, to translate... $somevar =

Reverting unpack('C*', “string”)

拟墨画扇 提交于 2019-12-19 18:53:43
问题 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 of bytes representing such string. Now I would like to know how to reverse such array back to the original string. <?php $array = unpack('C*', "odd string"); /*Output: Array ( [1] => 111 [2] => 100 [3] => 100 [4] => 32 [5] => 115 [6] => 116 [7] =>

Reverting unpack('C*', “string”)

女生的网名这么多〃 提交于 2019-12-19 18:53:17
问题 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 of bytes representing such string. Now I would like to know how to reverse such array back to the original string. <?php $array = unpack('C*', "odd string"); /*Output: Array ( [1] => 111 [2] => 100 [3] => 100 [4] => 32 [5] => 115 [6] => 116 [7] =>

When would you use unpack('h*' …) or pack('h*' …)?

一个人想着一个人 提交于 2019-12-18 13:01:41
问题 In Perl, pack and unpack have two templates for converting bytes to/from hex: h A hex string (low nybble first). H A hex string (high nybble first). This is best clarified with an example: use 5.010; # so I can use say my $buf = "\x12\x34\x56\x78"; say unpack('H*', $buf); # prints 12345678 say unpack('h*', $buf); # prints 21436587 As you can see, H is what people generally mean when they think about converting bytes to/from hexadecimal. So what's the purpose of h ? Larry must have thought

How does pack() and unpack() work in Ruby

旧巷老猫 提交于 2019-12-18 12:38:57
问题 In Ruby why we need array Packing ? How does directive help to do such packing? I ran some code in my console to see what and how directives looks like in Array packing.But the output is closely same with each directives. Then in core how they differs? irb(main):003:0> n = [ 65, 66, 67 ] => [65, 66, 67] irb(main):004:0> n.pack("ccc") => "ABC" irb(main):005:0> n.pack("C") => "A" irb(main):006:0> n.pack("CCC") => "ABC" irb(main):007:0> n.pack("qqq") => "A\x00\x00\x00\x00\x00\x00\x00B\x00\x00

pragma pack(1) nor __attribute__ ((aligned (1))) works

你。 提交于 2019-12-17 18:18:14
问题 My code used to work in the past, but now the struct size suddenly is 16 bytes. It used to be 13 bytes. I recently upgraded from Xcode 4.2 to Xcode 4.3.1 (4E1019). #pragma pack(1) struct ChunkStruct { uint32_t width; uint32_t height; uint8_t bit_depth; uint8_t color_type; uint8_t compression; uint8_t filter; uint8_t interlace; }; #pragma pack() STATIC_ASSERT(expected_13bytes, sizeof(struct ChunkStruct) == 13); I have tried unsuccesfully using #pragma pack(push, 1) /* struct ChunkStruct { ...

Creating and passing byte data to socket in PHP based on code for C++

点点圈 提交于 2019-12-14 03:56:40
问题 If that title didn't confuse you, I'll see what I can do here. I have the source of a C++ DLL that passes TCP traffic to a server. I believe all the relevant C++ code is below: #define HRD_MSG_SANITY1 0x1234ABCD #define HRD_MSG_SANITY2 0xABCD1234 typedef struct{ unsigned int nSize; unsigned int nSanity1; unsigned int nSanity2; unsigned int nChecksum; WCHAR szText[1]; } HRD_MSG_BLOCK; CString strMessage = "this is a test\n"; // I added this - the rest of the code // to determine this is