[futurebasic] RE: [FB] Sorting IP Numbers

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 2002 : Group Archive : Group : All Groups

From: "Edwards, Waverly" <Waverly.Edwards@...>
Date: Wed, 22 May 2002 21:00:35 -0400
Performance shouldnt suffer.

An IP address is just dotted decimal notation.
Its 32 bits broken up into 4 octets (groups of 8 bits)
If you look at an ip address in binary you can see
the break up of bits

10.0.1.3 (dotted decimal)
00001010 00000000 00000001 00000011 (binary)
0A       00       01       3 (dotted hex)

Your best bet is to deal with it as decimal number.
To convert from dotted decimal to decimal you would
bit shift in groups of 8

using the above number
(10 << 24) + (0 << 16) + (1 << 8) + (3 -- no shifting req)

dot-dec      decimal    hex
(10 << 24) = 167772160 (0A << 24)
(0 << 16)  = 0         (0 << 16)
(1 << 8 )  = 256       (1 << 8)
(3)        = 3         (3)
Total     = 167772419

To prove it put this into a scientific calculator and convert to decimal
00001010 00000000 00000001 00000011 (ignore spaces)

You will get the same result.  Once converted to decimal
you can sort to your hearts delight.


W.


If you took a scientific calculator and converted

-----Original Message-----
From: Michael Evans [mailto:evansmichael@...]
Sent: Wednesday, May 22, 2002 8:13 PM
To: futurebasic-associate.com
Subject: [FB] Sorting IP Numbers


Hello All:

I would like to sort a string array of IP numbers. Using a standard sort
won't work...

One method might be to convert the string to a long, sort the longs and
convert the longs back to strings.

I'm a little worried about performance....

Any ideas or hints cheerfully accepted...


Cheers,

----------------------------------------------------------------------------
Michael Evans
3301 Wood Valley Road, NW * Atlanta, GA, 30327-1515
Voice: (404) 846-9386 * Cell: (404) 229-3930 * Fax: (404) 240-0878
E-mail: <evansmichael@...>
----------------------------------------------------------------------------



--
To unsubscribe, send ANY message to <futurebasic-unsubscribe@...>