MySQL Lists are EOL. Please join:

 List: General Discussion « Previous MessageNext Message » From: Ray Date: June 19 2003 3:40pm Subject: Re: wierd sort query, how do you do it? (sort by ip proximity guess) View as plain text
```hehe,  guess there is 1 problem with this solution.  mysql doesn't do xor.
but found a ref saying
"a XOR b is mathematically equal to (a AND (NOT b)) OR ((NOT a) and b)"

On Thursday 19 June 2003 09:51, Matthew Smith wrote:
> Hi,
>
> If you convert the IP address into integers, then do an xor (exclusive or),
> you could call the resultant value the approximate 'distance' between the
> values.
>
> (think of the IP address in binary, any identical bits will result in 0,
> any differing will be 1.  This means that the most significant '1' will be
> the first dissimilar bit between the two IP addresses.  This is really what
> you are after.  However, including any lesser significant bits may well be
>
> OK, so how in SQL
>
> You need to create, on the fly
>
>
> (order does not matter) where they are both integers (mysql will use 64bit
> integer arithmetic).
>
> You just need to ORDER BY this value.
>
>
>
>
>
> Regards
>
>
> Matthew
>
>
> -----Original Message-----
> From: Ray [mailto:ray.list@stripped]
> Sent: 19 June 2003 15:33
> To: mysql@stripped
> Subject: wierd sort query, how do you do it? (sort by ip proximity
> guess)
>
>
> currently i have a table with an ip coloumn in text 123.45.67.89
> though it shouldn't be a big deal to convert it to binary, but was
> wondering if there is an easy way to sort by closeness to a given ip
>
> ie records that come out sorted as
> same class sub-c
> same class c
> same class c
> same class b
> same class a