How do I convert decimal to hexadecimal in Perl?

后端 未结 4 1675
野性不改
野性不改 2020-12-05 17:29

How can I convert a number, $d = 1024, in decimal to 0xFF in hex in Perl?

The d variable needs to be assigned to a different variable and b

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 18:04

    Caveat: sprintf overflows at 264 ≅ 1019, on 32-bit even already at only 232 ≅ 4×109.

    For large numbers, enable the lexical pragma bigint. as_hex is documented in Math::BigInt.

    use bigint;
    my $n = 2**65;
    print $n->as_hex;   # '0x20000000000000000'
    

提交回复
热议问题