pack

Perl pack/unpack and length of binary string

天涯浪子 提交于 2020-01-13 05:09:09
问题 Consider this short example: $a = pack("d",255); print length($a)."\n"; # Prints 8 $aa = pack("ddddd", 255,123,0,45,123); print length($aa)."\n"; # Prints 40 @unparray = unpack("d "x5, $aa); print scalar(@unparray)."\n"; # Prints 5 print length($unparray[0])."\n" # Prints 3 printf "%d\n", $unparray[0] ' # Prints 255 # As a one-liner: # perl -e '$a = pack("d",255); print length($a)."\n"; $aa = pack("dd", 255,123,0,45,123); print length($aa)."\n"; @unparray = unpack("d "x5, $aa); print scalar(

What is application's site of origin and when to use it

淺唱寂寞╮ 提交于 2020-01-10 21:18:26
问题 What is application's site of origin When to use it How is the build action of a resource file associated with it What is the difference between pack://application:,,, and pack://siteoforigin:,,, 回答1: The site of origin is the location (i.e. the physical folder) of the application executable assembly (i.e. the .exe that the user runs). The URI is thus relative to that folder. Example: You have C:\Programs\MyApp\MyApp.exe C:\Programs\MyApp\MyIcon.bmp C:\Programs\MyApp\Icons\MyOtherIcon.bmp The

Lua - packing IEEE754 single-precision floating-point numbers

故事扮演 提交于 2019-12-30 03:13:05
问题 I want to make a function in pure Lua that generates a fraction (23 bits), an exponent (8 bits), and a sign (1 bit) from a number, so that the number is approximately equal to math.ldexp(fraction, exponent - 127) * (sign == 1 and -1 or 1) , and then packs the generated values into 32 bits. A certain function in the math library caught my attention: The frexp function breaks down the floating-point value (v) into a mantissa (m) and an exponent (n), such that the absolute value of m is greater

Can someone explain to me the pack() function in PHP?

送分小仙女□ 提交于 2019-12-29 04:27:10
问题 I would like to know more about the pack() function in PHP: https://secure.php.net/manual/en/function.pack.php I know it packs data into binary, but I'm not sure what all those v V n N c C mean and I was wondering if someone could be so kind as to give me a practical demonstration when to use which formats? The online documentation, for a change, lacks of information, in my opinion. 回答1: Those represent how you want the data you are packing to be represented in binary format: so $bin = pack(

perl quick switch from quaternary to decimal

99封情书 提交于 2019-12-25 19:05:30
问题 I'm representing nucleotides A,C,G,T as 0,1,2,3, and afterwards I need to translate the sequence representing as quaternary to decimal. Is there a way to achieve this in perl? I'm not sure if pack/unpack can do this or not. 回答1: Base 4 requires exactly 2 bits, so it's easy to handle efficiently. my $uvsize = length(pack('J>', 0)) * 8; my %base4to2 = map { $_ => sprintf('%2b', $_) } 0..3; sub base4to10 { my ($s) = @_; $s =~ s/(.)/$base4to2{$1}/sg; $s = substr(("0" x $uvsize) . $s, -$uvsize);

Pack python library to one file [closed]

只谈情不闲聊 提交于 2019-12-25 02:47:22
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I want to pack pure python library into one source python script. (not exe, app, etc. I need exactly lib.py file) Is it possible? Which tools are exist for this? 回答1: Best is to pack all your python files into a zip: https://blogs.gnome.org/jamesh/2012/05/21/python-zip-files/ If you really want to, sure, it is

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

人走茶凉 提交于 2019-12-24 05:16:28
问题 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 = Button(root, text="Button1", command=something) btn1.pack() Is it possible to pack multiple widgets that are assigned to "root" in one swoop without using a for loop and explicitly naming the items , like this: for item in [btn1, btn2, label1, label2]:

Using Entry box with Tkinter in Grid manager?

依然范特西╮ 提交于 2019-12-23 22:08:00
问题 I'm trying to make a basic GUI using Tkinter and have an entry box next to my label using a Grid manager, but the window is not showing when I run my program if I use .grid() with my Entry object. It does work when I use .pack(), which is strange because I heard not to use .pack() when I have other things using .grid() in the same widget. But I do want to use .grid() because I want to be able to organize it how I want to. Code is below, I'm having trouble with Entry object showName. The

Simulate pack('J') in php < 5.6

我只是一个虾纸丫 提交于 2019-12-23 17:25:09
问题 I would need pack('J', $val) in php 5.5 but 'J' is supported in 5.6 onwards only. How can I simulate it in php-5.5? It is not really necessary to pack all 64 bits. My try does not seem to be correct (on Win7 64bit): pack('J', $val) === pack('N', 0) . pack('N', $val) 回答1: There's probably a smarter way to do this, but this works: // base_convert() will treat your value as a string here, // converting it from decimal to hexadecimal $hexStringValue = base_convert($your64bitInteger, 10, 16); //

Packing bools with bit field (C++)

隐身守侯 提交于 2019-12-23 13:02:55
问题 I'm trying to interface with Ada code using C++, so I'm defining a struct using bit fields, so that all the data is in the same place in both languages. The following is not precisely what I'm doing, but outlines the problem. The following is also a console application in VS2008, but that's not super relevant. using namespace System; int main() { int array1[2] = {0, 0}; int *array2 = new int[2](); array2[0] = 0; array2[1] = 0; #pragma pack(1) struct testStruct { // Word 0 (desired) unsigned a