Linux HAM/Amateur Radio development
 help / color / mirror / Atom feed
From: Hamish Moffatt <hamish@cloud.net.au>
To: John Ackermann N8UR <jra@febo.com>
Cc: linux-hams@vger.kernel.org
Subject: Re: Slightly OT: Perl question
Date: Sun, 16 Mar 2003 09:46:04 +1100	[thread overview]
Message-ID: <20030315224604.GA18830@silly.cloud.net.au> (raw)
In-Reply-To: <28850000.1047756287@[192.168.1.1]>

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 <hamish@debian.org> <hamish@cloud.net.au>

  reply	other threads:[~2003-03-15 22:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-15 19:24 Slightly OT: Perl question John Ackermann N8UR
2003-03-15 22:46 ` Hamish Moffatt [this message]
2003-03-15 22:54   ` John Ackermann N8UR

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030315224604.GA18830@silly.cloud.net.au \
    --to=hamish@cloud.net.au \
    --cc=jra@febo.com \
    --cc=linux-hams@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox