Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: bit string

by Zaxo (Archbishop)
on Jul 24, 2001 at 03:06 UTC ( #99225=note: print w/replies, xml ) Need Help??


in reply to bit string

Binary printf formats aren't supported in earlier versions. From v5.6.0 perldoc perldelta:

"Binary numbers supported

 Binary numbers are now supported as literals, in s?printf formats, and `oct()':

     $answer = 0b101010;
     printf "The answer is: %b\n", oct("0b101010");"

Update: forgot to put in the meat.
As a string:

$ perl -e '$c = 12;print reverse map {vec $c,$_,1} 0..8*length($c)-1; +' 0011001000110001

As a number:

$ perl -e '$c = 12;print reverse map {$c&1<<$_?1:0} 0..8;' 000001100

After Compline,
Zaxo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://99225]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2023-06-10 14:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (39 votes). Check out past polls.

    Notices?