That's a 64-bit int, soI'd like to use the "pack" function to produce what hoepfully will appear as "00 00 00 00 00 09 fe 00" when viewed in emacs with the "hexl-mode" turned on.
pack('q>', $_); # Signed pack('Q>', $_); # Unsigned
">" requires 5.10 (IIRC). "q" and "Q" require a 64-bit support. If you don't have a 64-bit support and your numbers aren't "very" large (<232), you could fake it using
pack('NN', $_<0 ? -1 : 0, $_); # Signed pack('NN', 0, $_); # Unsigned
In using "pack" I need to figure out how to fill with spaces ("\x20") before the actual hex representation of the 654848. Any suggestions?
You were talking about converting a number to a native int, now you're talking about its hex representation. It's not clear what you're asking here. Assuming this is a completely separate question,
sprintf('%8X', $_); # Padded with spaces sprintf('%08X', $_); # Padded with zeros
Update: Added answer to second question.
In reply to Re: zero fill with pack
by ikegami
in thread zero fill with pack
by Spooky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |