Subject: Re: Network mask contiguity

From: Igor Miroshnik <[email-masked]>
Date: Mon, 15 Dec 2003 12:00:34 -0500

Vishwas, Venkata, Fred, Paul - thank you! It works wonderfully.

Igor

On Mon, 15 Dec 2003 07:43:34 -0800, Fred Baker <[email-masked]> wrote:

>At 12:44 PM 12/14/2003, Igor Miroshnik wrote:
>>Is anybody familiar with an efficient algorithm testing network mask
>>contiguity?
>
>On a 32 bit two's complement machine, one can isolate the least significant
>"1" in a number by
>
>         lso = (mask) & (-mask);
>
>and test 32 bit mask contiguity by
>
>         0 == mask + lso
>
>Extending to a 64 bit machine should be obvious: test for the mask itself
>being zero, or the sum being 0x0000000100000000
>
>for a 128 bit mask, the simple approach is to structure the number as four
>unsigned 32 bit ints. Some may be equal to zero, and some may be equal to
>0xFFFFFFFF. The one in the middle meets the rule above.