| От | Anton Nikiforov |
|---|---|
| Тема | Re: int to inet conversion |
| Дата | |
| Msg-id | 4392DF5B.7010204@nikiforov.ru обсуждение исходный текст |
| Ответ на | Re: int to inet conversion (Martijn van Oosterhout <kleptog@svana.org>) |
| Ответы |
Re: int to inet conversion
|
| Список | pgsql-general |
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 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, Sorry, did not quite catch. t in this case is int, and there is no log2(int) function..... Best regards, Anton
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера