From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
---|---|
To: | Anton Nikiforov <anton(at)nikiforov(dot)ru> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: int to inet conversion |
Date: | 2005-12-04 11:54:15 |
Message-ID: | 20051204115409.GC4883@svana.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sun, Dec 04, 2005 at 02:09:53PM +0300, Anton Nikiforov wrote:
> Sorry for my stupidity but, maybe there is a function that converts mask
> stored in int format to a numer of bits? ;)
> Your function easyly convert this mask to dot decimal notation, but how
> to count the number of 1 in it?
No, but you can write one the same way like so:
Let i be your input.
Calculate t = -i.
If i is in the right format, t will have exactly one bit set.
Test this with t <> 0 and (t & i) == t
If that's ok, then your answer is 32 - log2(t)
Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.
From | Date | Subject | |
---|---|---|---|
Next Message | Anton Nikiforov | 2005-12-04 12:21:47 | Re: int to inet conversion |
Previous Message | Anton Nikiforov | 2005-12-04 11:09:53 | Re: int to inet conversion |