Re: [GENERAL] int to inet conversion

2005-12-04 Thread Anton Nikiforov
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 ans

Re: [GENERAL] int to inet conversion

2005-12-04 Thread Martijn van Oosterhout
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)

Re: [GENERAL] int to inet conversion

2005-12-04 Thread Anton Nikiforov
Martijn van Oosterhout wrote: 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

Re: [GENERAL] int to inet conversion

2005-12-04 Thread Martijn van Oosterhout
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

Re: [GENERAL] int to inet conversion

2005-12-04 Thread Anton Nikiforov
Tom Lane wrote: Anton Nikiforov <[EMAIL PROTECTED]> writes: is there any function that can translate INT to INET type? Nothing built-in, and given the fact that "inet" no longer means "IPv4", it's unlikely we'd add one in the future. But there's nothing stopping you from adding one of your

Re: [GENERAL] int to inet conversion

2005-12-04 Thread Anton Nikiforov
Tom Lane wrote: Anton Nikiforov <[EMAIL PROTECTED]> writes: is there any function that can translate INT to INET type? Nothing built-in, and given the fact that "inet" no longer means "IPv4", it's unlikely we'd add one in the future. But there's nothing stopping you from adding one of your

Re: [GENERAL] int to inet conversion

2005-12-03 Thread Tom Lane
Anton Nikiforov <[EMAIL PROTECTED]> writes: > is there any function that can translate INT to INET type? Nothing built-in, and given the fact that "inet" no longer means "IPv4", it's unlikely we'd add one in the future. But there's nothing stopping you from adding one of your own. For example r