larryk has asked for the wisdom of the Perl Monks concerning the following question:
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!
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);
Any help much appreciated,
larryk perl -le "s,,reverse killer,e,y,rifle,lycra,,print"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Byte-order and packing numbers into strings
by demerphq (Chancellor) on Jan 24, 2002 at 22:13 UTC | |
by tadman (Prior) on Jan 24, 2002 at 23:09 UTC | |
by demerphq (Chancellor) on Jan 24, 2002 at 23:41 UTC | |
|
Re: Byte-order and packing numbers into strings
by theorbtwo (Prior) on Jan 25, 2002 at 09:48 UTC |