在Perl中是否有等效的`int,short,long`?

eve*_*box 9 perl

64位系统:

$i=2;print ~$i; # 18446744073709551613
Run Code Online (Sandbox Code Playgroud)

32位系统:

$i=2;print ~$i; # 4294967293
Run Code Online (Sandbox Code Playgroud)

我怎样才能制作$i32位?

在任何系统中,我都需要在Perl中进行便携式按位操作.

hob*_*bbs 10

只是按位 - 和结果0xffffffff.这对32位系统没有影响,并且在64位系统上为您提供低位32位,这是您想要的答案.


sjs*_*sjs 1

对于 Perl 中的可移植按位运算,请查看CPAN 上的Bit::Vector 库

它支持多种按位运算,例如:

use Bit::Vector;

my $vector = Bit::Vector->new_Dec(32, "2"); # 32-bit vector for the decimal value 2
$vector->Negate($vector);
Run Code Online (Sandbox Code Playgroud)