Perl supports something called bit vectors. Essentially, it's just a way to treat a string of bits as an arbitrary length byte.
You'd use something like $bv = pack('B*', $byte); to turn your string into a bit vector. You can use vec to access individual elements.
If you were to do that, it might simplify your code somewhat. The first regex could be replaced with:
if ((vec($bv, 0, 1) == 1) and (vec($bv, 4, 1) == 0)) {
# do something
}
That's untested, as I've not found a good use for this yet.
I'd probably turn your string into an integer and use bitwise operations to work on it.
Update: After studying this a bit more, it'll take more work to use vec to replace the regex. Use logical and, not, or, and xor as tye suggests. The bit-shifting operands will also come in handy.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.