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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I prototype a lot of my C microcontroller code in Perl, and for that purpose so I, and others might benefit, I wrote Bit::Manip. That contains code that has to be compiled, so for a Pure Perl version, there's Bit::Manip::PP.

It does all the things that we who have to do bitwise operations from time-to-time but not as a profession (or often enough to remember how) we need to do.

Here's an example of turning 'off' a bit:

Code:

use strict; use warnings; use Bit::Manip qw(:all); my $num = 0b11100111; # or literal 231 my $bit_position = 6; my $flipped = bit_off($num, $bit_position); printf("orig: %b\n", $num); printf("flipped: %b\n", $flipped);

Output:

steve@maezi ~/scratch >perl bit.pl orig: 11100111 flipped: 10100111

In reply to Re: How can I set a bit to 0 ? by stevieb
in thread How can I set a bit to 0 ? by bartender1382

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2023-10-04 23:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?