Re: Slightly OT: Perl question

From: Hamish Moffatt (terhi.victor@logonet.com)
Date: Sun Mar 16 2003 - 00:46:04 EET

  • Next message: John Ackermann N8UR: "Re: Slightly OT: Perl question"

    On Sat, Mar 15, 2003 at 02:24:47PM -0500, John Ackermann N8UR wrote:
    > I need to:
    >
    > (a) test whether one bit of a byte is set or not (e..g, is bit 5 of $myvar
    > a 1 or a 0);
    >
    > and
    >
    > (b) do a binary AND of two bytes (in other words, apply a bitmask).

    Binary AND is the "&" operator as in C. So

    $c = $a & $b;
    $y = $x & 0xFF;

    etc achieves (b), and similarly for (a),

    if ($myvar & 0x20) {
        ....
    }

    or perhaps more readably:

    if ($myvar & (1 << 5)) {
        ....
    }

    Hamish

    -- 
    Hamish Moffatt VK3SB <terhi.victor@logonet.com> <uupjf@intomartgfk.nl>
    -
    To unsubscribe from this list: send the line "unsubscribe linux-hams" in
    the body of a message to gngfuu.hjxobgglnp@kerailya.tunkki.fi
    More majordomo info at  http://vger.kernel.org/majordomo-info.html
    



    This archive was generated by hypermail 2b30 : Sun Mar 16 2003 - 01:04:13 EET