converting I.P. Addresses to integer
[1/5] from: tim::johnsons-web::com at: 31-Jul-2000 21:17
Hello:
How can an I.P. address be converted to an integer?
to-integer 207.69.132.8
Is illegal as far as rebol is concerned, but
when you really think of it:
207.69.132.8 really represents a 32-bit integer
right?
So, is there any easy way to do this, or do I have
to convert it to a string, parse it and to some
bit-wise shifting?
TIA
Tim
[2/5] from: larry:ecotope at: 31-Jul-2000 23:33
Hi Tim
>> tup-to-num 207.69.132.8
== 3477439496
HTH
-Larry
-----------code-------------------
REBOL [
Title: "Convert IP to number"
Author: "Larry Palmiter"
Date: 31-Jul-2000
File: %tup-to-num.r
Comment: {
Must be decimal because REBOL
does not support 32 bit unsigned.
Assumes 4 items in tuple
}
]
tup-to-num: func [x /local out][
out: 0.0
x: head reverse parse to-string x "."
repeat j 4 [
out: out + (256.0 ** (j - 1) * to-integer x/:j)
]
]
[3/5] from: kgd03011:nifty:ne:jp at: 2-Aug-2000 1:00
Hi Larry,
You wrote:
>tup-to-num: func [x /local out][
> out: 0.0
<<quoted lines omitted: 3>>
> ]
>]
How about ... ?
tup-to-num2: func [x /local z out][
out: 0.0
repeat j length? x [
out: out * 256 + pick x j
]
]
See you,
Eric
[4/5] from: tim:johnsons-web at: 1-Aug-2000 7:48
Thanks Larry:
I sure appreciate your help. I'm cramming
to but out an online class on rebol and I needed that.
You just saved me I half hour or so of my time.
Regards :)
Tim
At 11:33 PM 7/31/00 -0700, you wrote:
[5/5] from: larry:ecotope at: 1-Aug-2000 10:29
Thanks Eric
Excellent. Also faster. I thought about changing to Horner's method (what
you used) but I was too tired. BTW, the local 'z is now superfluous.
Cheers
-Larry
----- Original Message -----
From: <[KGD03011--nifty--ne--jp]>
To: <[list--rebol--com]>
Cc: Larry Palmiter <[larry--ecotope--com]>
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted