in reply to zero fill with pack
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: zero fill with pack
by Spooky (Beadle) on Jun 22, 2010 at 18:03 UTC | |
by ikegami (Patriarch) on Jun 22, 2010 at 18:34 UTC | |
by Spooky (Beadle) on Jun 23, 2010 at 16:54 UTC | |
by Spooky (Beadle) on Jun 25, 2010 at 13:21 UTC | |
by Spooky (Beadle) on Jun 25, 2010 at 15:28 UTC | |
|
Re^2: zero fill with pack
by BrowserUk (Patriarch) on Jun 22, 2010 at 21:54 UTC |