I hope that this can help clarify things... The issue is whether you have a string or a number. A couple of demo's:
#!/usr/bin/perl use warnings; use strict; #prints "0" becaus 0x30 is "0" in ASCII my $char = "\x30"; #quotes makes $char a "character" # result being the number "0" in ASCII # which translates to numeric 0! print "$char\n"; #prints "0" printf "%08b\n", $char; #still prints "0"!! print "\nNow, 0x30 as a number, not a character\n"; #without the quotes, we have a binary number... my $char2 = 0x30; print "$char2\n"; #prints 48 (decimal 0x30) printf "%08b\n", $char2; #prints "00110000" __END__ 0 00000000 Now, 0x30 as a number, not a character 48 00110000
Sometimes the hex function can be useful.
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my @strings=("ab30ff","30","ab1a30"); for (@strings){ $_=hex $_; } foreach my $hex (@strings) { printf "%08b\n", $hex; } __END__ 101010110011000011111111 00110000 101010110001101000110000

In reply to Re: while loop on binary : \x30 by Marshall
in thread while loop on binary : \x30 by sphalaris

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.