in reply to Flipping bits and using flags
Runing a bitwise and will simply tell you that there are some bits that are up in both the $bit_flat as within one of the values in the @bit_list.#!/usr/bin/perl use strict; use warnings; my $bit_flag = 5; #0b101 my @bit_list = qw( 1 2 4 8 16 ); # Assuming you want to test for truth of my above statment # later in the application, binary 1/0 will work fine my $bit_flipped = ( grep{ $bit_flag & $_ } @bit_list ) ? 1 : 0; # Continue on with the application
print$_ for(map{chr($_)}split(/\s+/,join(/\B?:\w+[^\s+]/,<DATA>))); __DATA__ 67 111 100 101 32 80 101 114 108
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Flipping bits and using flags
by BMaximus (Chaplain) on Mar 24, 2006 at 01:59 UTC |