Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How can I set a bit to 0 ?

by LanX (Saint)
on May 26, 2022 at 22:36 UTC ( #11144211=note: print w/replies, xml ) Need Help??


in reply to How can I set a bit to 0 ?

> What I don't know how to do, nor find on Google,is turn off a specific bit whether it is set or not.

you "mask" (using & the "bitwise-and") with a bitvector which is only 0 if and only if you want to turn off.

DB<22> $in = 0b10101010 + + + DB<23> $mask = 0b11110000 # 1 keep 0 erase + + + DB<24> printf "%b", $in & $mask + 10100000
for more see Mask (computing)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2023-09-23 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?