in reply to zero fill with pack

Note: The print unpack 'H*', is just a simulation of hexl-mode. It's the pack bit which does the work:

print unpack 'H*', pack 'Q>', 654848;; 000000000009fe00 ## With a Perl that doesn't support 64-bit ints (Q). ## Corrected &.v.% per ikegami++ print unpack 'H*', pack 'NN', int( $n / 2**32 ), $n % 0xffffffff;; 000000000009fe00

Replies are listed 'Best First'.
Re^2: zero fill with pack
by ikegami (Patriarch) on Jun 22, 2010 at 16:51 UTC
    $n & 0xffffffff won't work. You need $n % 0xffffffff.

      Works for my (64-bit) Perl ;)

        Yes, but that code was specifically written for "a Perl that doesn't support 64-bit ints (Q)." The bitwise ops (i.e. "&") currently require native integer arguments, and those can be at most 0xFFFFFFFF in such a Perl.