I need to break unsigned 32-bit values into 4 parts: (from the msb) 14-bits, 6-bits, 6-bits, 6-bits; (using perl rather than I::C or XS). That can be done as follows:
#! perl -slw
my $n = 0x80061861;
my $top14 = ( $n & 0xfffc0000 ) >> 18;
my $nxt6 = ( $n & 0x0003f000 ) >> 12;
my $mid6 = ( $n & 0x00000fc0 ) >> 6;
my $bot6 = ( $n & 0x0000003f );
print "$n => $top14 : $nxt6 : $mid6 : $bot6";
2147883105 => 8193 : 33 : 33 : 33
But I need to do this millions of times, so I'm looking to see if there is a more efficient way? (I don't care if I get 4 separate variables or an array with 4 values.)
Note: This is for me; no one else. Elegance, readability and maintainability are simply not considerations here. Just speed.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||