Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

larryk's scratchpad

by larryk (Friar)
on Jun 05, 2004 at 11:58 UTC ( [id://361503]=scratchpad: print w/replies, xml ) Need Help??

The Code
#!perl use strict; use warnings; sub both_byte_orders_32 { my $data = shift; $data = pack 'H*', sprintf '%08x', $data; return reverse($data).$data } print both_byte_orders_32(305419896);
Currently...
I need to format an integer into an 8-byte hexadecimal string as follows: if hex representation is (st uv wx yz) the formatted string must be (yz wx uv st st uv wx yz).

e.g. 305419896 in hex is (12345678) so formatted string should be (78 56 34 12 12 34 56 78)

The Question
although this works I have a nagging suspicion that this isn't The Best Way (tm) - is there some way to incorporate the reversing (little/big endian or something) into the pack/sprintf somehow - pack is still mysterious to me!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-12-10 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (56 votes). Check out past polls.