Thanks for reply. Stories of bit is a little bit hard for me. Please point out if I am saying something wrong.

How/what?

I was wrong. I was confused with little endian and big endian. Here OP expects it's input bit array as Big Endian(N) and descending bit order(B).

printf "0x%x\n",                #hex
    unpack("N",                 #unpack it as 32bit int ,big endian
        pack("B32",             #pack it as MSB descending bit, 32bit inte
            sprintf("%032s",    #32 length bit string
                join('',
                    @rand1))));

So, left pad works fine, even if it was an array of 16bit.
my $num;
$num=pack('n',7); #16bit short Big endian, it's value is 7
printf "big endian, descending bit order:%s\n", unpack('B16',$num);
printf "big endian, ascending  bit order:%s\n", unpack('b16',$num);
printf "unsigned short=%d\n",unpack('n',pack('B16', unpack('B16', $num)));

printf "right pad:%s\n", unpack('B16',$num) . '0' x 16;
printf "32bit right pad=%d\n",unpack('N',pack('B32', unpack('B16',$num) . '0' x 16));
#==> this prints "32bit right pad=458752"
printf "left  pad:%s\n", '0' x 16 . unpack('B16',$num);
printf "32bit left  pad=%d\n",unpack('N',pack('B32', sprintf('%032d', unpack('B16',$num)))
#==> this prints "32bit left  pad=7"
You are the same anonymous with this.
print  '0x'. unpack 'H*', pack("B32", substr("0" x 32 . join('',@rand1), -32));
So, you are going to say: If you need it's hexadecimal values, there is no need for decimal( unpack 'N') -> hexadecimal conversion( printf %x), just print it as hex( unpack 'H').

I am going to see your links. Thanks for reply.


In reply to Re^4: array of binaries to hex conversion by remiah
in thread array of binaries to hex conversion by bebe

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.