Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: binary string

by rir (Vicar)
on Jan 15, 2009 at 19:16 UTC ( [id://736649]=note: print w/replies, xml ) Need Help??


in reply to binary string

I'm not sure I'm getting how you want to handle the 8th or most significant bit.
#!/usr/bin/perl use warnings; use strict; sub a_half_nibble_is_00 { my $str = shift; # XXX bounds my @masks = map {chr $_} ( 3, 12, 48, 192 ); # XXX magic local $_; return !! grep { (~($str.'')&$_) eq $_ } @masks; # L::U::first } my @chars = map { chr $_ } (0 .. 127 ); for my $str ( @chars) { my $flag = a_half_nibble_is_00( $str) ? '*' : '' ; printf "%2s%4d >%08b< >%s<$/", $flag, ord($str), ord($str), $str; }

Be well,
rir

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-16 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found