Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: first 5 bits and last 3 bits

by fisher (Priest)
on Jul 26, 2011 at 12:38 UTC ( #916754=note: print w/replies, xml ) Need Help??


in reply to first 5 bits and last 3 bits

Use bitmask and bitwise boolean operations.
fisher% perl -e 'my $byte=129; my $first5=$byte&0xf8; printf "%08b, %d +\n", $byte, $first5;' 10000001, 128

Replies are listed 'Best First'.
Re^2: first 5 bits and last 3 bits
by DrHyde (Prior) on Jul 27, 2011 at 09:26 UTC
    If you're creating a bitmask, it's clearer to say 0b11111000 than 0xf8.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2020-11-24 21:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?