Subject: Re: Network mask contiguity

From: Igor Miroshnik <[email-masked]>
Date: Mon, 15 Dec 2003 08:50:32 -0500

Vishwas,

Thank you for reply. I tried to launch this question to the Networking
list, but it didn't seem to be intact.

I absolutely agree with your method, but it feels that there must be a trick
with no iteration inside. A couple of lines, some bitwise magic... Don't
you consent?

Thank you,
Igor

On Mon, 15 Dec 2003 19:08:01 +0200, Vishwas Manral <[email-masked]>
wrote:

>Hi Igor,
>
>I dont think this question belongs here, however just thinking of it I
found
>this could be fairly optimal. From the right start till u find the bit 1
>(could make this more optimal), compare the value as stored in an array of
>index the number of bits. The value could be 2^32 - 2^x at index x.
>
>You could start with looking at the more possible prefix mask lengths, like
>24 bits etc.
>
>Thanks,
>Vishwas
>
>-----Original Message-----
>From: Mailing List [mailto:[email-masked]]On Behalf Of Igor
>Miroshnik
>Sent: Sunday, December 14, 2003 10:44 PM
>To: [email-masked]
>Subject: Network mask contiguity
>
>
>Group,
>
>Is anybody familiar with an efficient algorithm testing network mask
>contiguity?
>
>Thank you,
>Igor
>
>---
>Outgoing mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.551 / Virus Database: 343 - Release Date: 12/11/2003

---

From: Paul Wells <[email-masked]>
Date: Mon, 15 Dec 2003 10:29:53 -0600

Igor,

I believe that for a non-zero network mask m, the condition you want is:

(~m & (~m + 1)) == 0

- Paul