Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Extracting Bit Fields (Again)

by Aristotle (Chancellor)
on Oct 12, 2005 at 05:27 UTC ( [id://499380]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    $D3 = ( $num >> 0 ) & ( 1 << 4 ) - 1;  # 4 bits starting at bit 0
    $D2 = ( $num >> 4 ) & ( 1 << 3 ) - 1;  # 3 bits starting at bit 4
    $D1 = ( $num >> 7 ) & ( 1 << 1 ) - 1;  # 1 bit  starting at bit 7
    
  2. or download this
    $D3 = $num & ( 1 << 4 ) - 1;  # 4 bits starting at bit 0
    $num = $num >> 4;
    ...
    
    $D1 = $num & ( 1 << 1 ) - 1;  # 1 bit  starting at bit 7
    $num = $num >> 1;
    
  3. or download this
    @width = ( 4, 3, 1 );
    
    ...
    
    $D1 = $num & ( 1 << $width[ 2 ] ) - 1;  # 1 bit  starting at bit 7
    $num = $num >> $width[ 2 ];
    
  4. or download this
    sub bitfield {
        my ( $num, @field ) = @_;
    ...
        }
        return @value;
    }
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found