Re: int to inet conversion

From: Anton Nikiforov <anton(at)nikiforov(dot)ru>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
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-05 01:36:28
Message-ID: 4393999C.5000101@nikiforov.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Martijn van Oosterhout wrote:

> 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,
Thanks alot!

Best regards,
Anton

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Havasvölgyi Ottó 2005-12-05 01:45:34 Some rare questions
Previous Message Jonathan Schreiter 2005-12-05 01:32:10 Re: postgresql jdbc connect via hostname instead of just ip