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.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

In reply to Re: Bit order by BrowserUk
in thread Bit order by spoulson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.