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 14:23:19 |
Message-ID: | 20051204142313.GA698@svana.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sun, Dec 04, 2005 at 03:21:47PM +0300, Anton Nikiforov wrote:
> Martijn van Oosterhout wrote:
> >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,
> Sorry, did not quite catch.
> t in this case is int, and there is no log2(int) function.....
But there is a log(x,y) function, so log(2,t) would work also. Note
that 255.255.255.0 stored as integer is -256.
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 | Bruno Wolff III | 2005-12-04 15:56:16 | Re: Slow COUNT |
Previous Message | Tino Wildenhain | 2005-12-04 13:40:49 | Re: Slow COUNT |