如何解包(64位)的无符号长64位的Perl? [英] How to unpack (64-bit) unsigned long in 64-bit Perl?
问题描述
我试图解开无符号长值,即从C程序中通过SysV的传递到Perl脚本:: IPC。
I'm trying to unpack unsigned long value, that is passed from C program to Perl script via SysV::IPC.
有已知值是正确的(Ⅰ做了一个试验,它发送相同的值分成两个队列,一个被Perl读,第二被C的应用程序),以及所有predecessing值被正确地读出(用<$ C $ ç>问:而不是我!
64位int工作)。
It is known that value is correct (I made a test which sends same value into two queues, one read by Perl, second by C app), and all predecessing values are read correctly (used q
instead of i!
to work with 64-bit int).
有还已知的PHP中有错误类似的东西的(搜索无符号长在64位机器)(似乎是相似的: <一href="http://stackoverflow.com/questions/3265285/php-pack-unpack-64bit-int-on-64bit-architecture">PHP:在64位架构包/解包64位INT)
It is also known that PHP had something similar in bugs (search for "unsigned long on 64 bit machines") (seems to be similar: PHP: pack / unpack 64bit int on 64bit architecture)
参数到目前为止测试:
- .. Q(=一些值是大于预期)
- .. L(= 0)
- ..升! (=较大值)
- .. L(= 0)
- ..升! (=较大值)
- ..的1N! (= 0)
- .. N,..N! (= 0)
使用BIGINT;使用BIGNUM;
- 不影响
详细信息:
-
的sizeof(unsigned long类型)
= 8; -
数据:: Dumper-&gt;新建([$ thatstring]) - &GT; Useqq(1) - &GT;转储();
很多空字节沿一些有意义的.. - 在byteorder ='12345678';
sizeof(unsigned long)
= 8;Data::Dumper->new([$thatstring])->Useqq(1)->Dump();
a lot of null bytes along some meaningful..- byteorder='12345678';
解决方案:
- x4Q
与填充4个字节
Solution:
- x4Q
with padding 4 bytes.
推荐答案
解决的办法很简单:加入 x4Q
来跳过前实际值四个字节;需要更直观地认为填充/比对。
The solution was simple: added x4Q
to skip four bytes before actual value; need to more visually think of padding/alignment..
这篇关于如何解包(64位)的无符号长64位的Perl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!