in reply to Bit order
The problem with N versus V is that it swaps byte-order not bit-order. ie.
printf '%08x', unpack 'N', $Vpacked printf '%08x', unpack 'N', $Npacked printf '%08x', unpack 'V', $Vpacked printf '%08x', unpack 'V', $Npacked 04030201 01020304 01020304 04030201
So, depending on you local endianess and that of the source, and whether you want the bits in l-r or r-l order, there are four possible permutations to consider.
$num = 0x01020304; $Npacked = pack 'N', $num; $Vpacked = pack 'V', $num; print map{ vec $Vpacked, $_, 1 } 0 .. 31 print map{ vec $Npacked, $_, 1 } 0 .. 31 print map{ vec $Vpacked, 31 - $_, 1 } 0 .. 31 print map{ vec $Npacked, 31 - $_, 1 } 0 .. 31 00100000 11000000 01000000 10000000 10000000 01000000 11000000 00100000 00000001 00000010 00000011 00000100 00000100 00000011 00000010 00000001
Hopefully one of these will be what your looking for...unless you source is one of the 6-bit byte/3-byte word machines in which case all bets are off:)
Note: I broke up the output into 8's manually. Couldn't think of a clean way of doing it without obscuring the code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bit order
by spoulson (Beadle) on May 21, 2003 at 20:54 UTC |