Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Making all nibble zero lower than the offset

by trippledubs (Deacon)
on Nov 20, 2018 at 05:19 UTC ( [id://1226048]=note: print w/replies, xml ) Need Help??


in reply to Making all nibble zero lower than the offset

#!/usr/bin/env perl use strict; use warnings; my $data = 0b1111_1111_1111; my $offset = 8; my $nibble_mask = 0xF; while (not 1<<$offset-1 & $nibble_mask) { $data ^= $nibble_mask; $nibble_mask <<= 4; } $data = $data ^ $nibble_mask; printf("%b\n",$data);

Replies are listed 'Best First'.
Re^2: Making all nibble zero lower than the offset
by trippledubs (Deacon) on Nov 20, 2018 at 18:46 UTC
    How naive I was to loop through looking for something already given...
    #!/usr/bin/env perl use strict; use warnings; my $data = 0b1111_1111_1111; my $offset = 5; my $mask = hex 'F' x ($offset % 4 == 0 ? $offset / 4 : $offset / 4 + 1 +); printf("%b\n",$data ^ $mask);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1226048]
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: (9)
As of 2024-03-28 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found