unpack

“Unpacking” in C

不想你离开。 提交于 2019-12-24 12:34:53
问题 I am working on rewriting a script from python to C . I'm relatively new to C. I have a variable in PYTHON which contains this values: x = [chr(113),chr(80),chr(191),chr(70)] y = "".join(x) This will return this value of y: y = qP¿F #this is string Now what I do is unpack this variable, store it to variable z to get the results that I wanted. Like this: z = struct.unpack("<f",y) print z[0] #unpack returns a tuple of size 1 The value that I get is: x = 24488.2207 which for my case is correct.

How to unpack results from `Pool.map()`?

点点圈 提交于 2019-12-24 07:56:27
问题 I've got a function (preprocess_fit) that will first preprocess a data set (i.e. smoothing, baseline correction, and filters out bad data). The function then takes an initial guess for a parameter and then iterates through guesses to find the optimised fit and then returns const1, const2. The function also calculates a bunch of other parameters but they are not returned in this instance. I then need to loop this function over all files in a directory (~1000 files). I do this by using the

How to unpack all rar archives in all subfolders of a folder and then delete the archives?

谁都会走 提交于 2019-12-21 20:34:06
问题 I want to unpack all files in some subfolders which are in a main folder, delete the xxx.rar files after unpacking and move the folder with the files to another location. Main Folder Sub Folder1 (with .rar files) Sub Folder2 (with .rar files) Sub Folder3 (with .rar files) This my batch script and works so far. SET "sourcefolder=C:\Users\Unpack" FOR /R %sourcefolder% %%X in (*.rar) do ( pushd "%%~dpX" "C:\Program Files\WinRAR\Rar.exe" x -y "%%X" "*.*" && del "*.rar" popd ) for /d /r

Python: reading 12 bit packed binary image

妖精的绣舞 提交于 2019-12-21 16:23:40
问题 I have a 12 bit packed image from a GigE camera. It is a little-endian file and each 3 bytes hold 2 12-bit pixels. I am trying to read this image using python and I tried something like this: import bitstring import numpy with open('12bitpacked1.bin', 'rb') as f: data = f.read() ii=numpy.zeros(2*len(data)/3) ic = 0 for oo in range(0,len(data)/3): aa = bitstring.Bits(bytes=data[oo:oo+3], length=24) ii[ic],ii[ic+1] = aa.unpack('uint:12,uint:12') ic=ic+2 b = numpy.reshape(ii,(484,644)) In short:

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] =>

Default value in Python unpacking

血红的双手。 提交于 2019-12-19 06:07:12
问题 Is there a way to have a default value if the number of values to unpack is too little compared to the variable list? For example: a, b, c = read_json(request) This works if read_json returns an array of three or more variable. If it only returns two, I get an exception while assigning c . So, is there a way to set c to a default value if it can't be unpacked properly? Something like: a, b, (c=2) = read_json(request) Which is similar to what you do when defining a function with default

struct.unpack with bytearray's

时光毁灭记忆、已成空白 提交于 2019-12-19 04:12:59
问题 I wrote an application that uses struct.unpack on byte arrays. Running it on my machine using python 2.7.5 it works well: >>> data bytearray(b'\x07\x00\x00\x00\x00\x00\x00\x00') >>> struct.unpack("<Q", data) (7,) however, I tried to use it with a python version 2.7.3 I got an exception: error: unpack requires a string argument of length 8 I need to explicitly cast the bytearray to string before unpacking it. Is this related to the python version change? the struct manual says nothing about

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