| Public Scratchpad | Download, Select Code To D/L |
Currently...#!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);
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!