Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #19995
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Double integer input |
| Date | 2013-02-24 22:05 +0000 |
| Organization | NewsGuy - Unlimited Usenet $19.95 |
| Message-ID | <kge2rk0na2@enews1.newsguy.com> (permalink) |
| References | <dddbd9b1-de8c-4e44-ae90-b67572a1bb53@googlegroups.com> <kg6cg1$a3b$1@speranza.aioe.org> <brWdnQmhLoxDJ7vMnZ2dnUVZ_uKdnZ2d@supernews.com> <0a4903d5-bd3c-44f4-8ad3-03e5224affb7@e11g2000vbv.googlegroups.com> |
Alex McDonald wrote:
> : ip-seg ( addr len -- addr' len' n ) \ IP segment before .
> dup >r \ save length
> 0 0 2swap >number \ convert to number
> 2swap d>s \ save string & convert to single
> over r> <> \ check lengths differ before & after
> over 0 256 within \ and range check it
> and 0= throw \ flag; true=error
> ;
>
> : ipv4-number? ( addr len -- d ) \ convert ip address
> 8 24 do \ 3 dotted segments
> ip-seg \ convert up to dot
> i lshift \ shift the value,
> -rot \ addr string to top
> dup 0= throw \ string too short?
> over c@ '.' <> throw \ check for a dot, error if not
> 1 /string \ move past .
> -8 +loop \ next shift
> ip-seg \ convert what's left
> -rot throw \ should be nothing left
> drop or or or s>d \ ors to get result, make double
> ;
>
>
> Not an array, but a single number in this case. IPv4 can also be 3 or
> 2 or 1 section, but they are rarely seen.
Horrible. Simply, inexcusably, criminally horrible.
That looks even more low-level than assembly language.
No rational person would want to code that way.
It's so much easier in other languages.
And the code is not even correct.
s" 1.254.253.252" ipv4-number? ud. 33488380 ok
s" 255.254.253.252" ipv4-number? ud. 18446744073709485564 ok
Ruby:
def ip_to_number str
str.split( "." ).reduce(0){|n,s| n*256 + s.to_i }
end
ip_to_number( "1.254.253.252" )
==>33488380
ip_to_number( "255.254.253.252" )
==>4294901244
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Double integer input Rosangela Medeiros da Silva <rosangelamesil@gmail.com> - 2013-02-13 18:15 -0800
Re: Double integer input Rosangela Medeiros da Silva <rosangelamesil@gmail.com> - 2013-02-14 02:07 -0800
Re: Double integer input Coos Haak <chforth@hccnet.nl> - 2013-02-14 16:18 +0100
Re: Double integer input Coos Haak <chforth@hccnet.nl> - 2013-02-14 16:27 +0100
Re: Double integer input "A. K." <akk@nospam.org> - 2013-02-14 20:54 +0100
Re: Double integer input Coos Haak <chforth@hccnet.nl> - 2013-02-14 23:20 +0100
Re: Double integer input "Ed" <invalid@nospam.com> - 2013-02-22 11:00 +1100
Re: Double integer input "Elizabeth D. Rather" <erather@forth.com> - 2013-02-21 14:24 -1000
Re: Double integer input Bernd Paysan <bernd.paysan@gmx.de> - 2013-02-22 01:50 +0100
Re: Double integer input anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-22 15:35 +0000
Re: Double integer input Bernd Paysan <bernd.paysan@gmx.de> - 2013-02-22 18:15 +0100
Re: Double integer input stephenXXX@mpeforth.com (Stephen Pelc) - 2013-02-22 19:02 +0000
Re: Double integer input anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-23 17:27 +0000
Re: Double integer input Bernd Paysan <bernd.paysan@gmx.de> - 2013-02-24 03:42 +0100
Re: Double integer input "Elizabeth D. Rather" <erather@forth.com> - 2013-02-22 09:08 -1000
Re: Double integer input anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-23 16:15 +0000
Re: Double integer input stephenXXX@mpeforth.com (Stephen Pelc) - 2013-02-23 17:35 +0000
Re: Double integer input anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-25 15:25 +0000
Re: Double integer input albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-02-23 19:34 +0000
Re: Double integer input "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2013-02-23 18:35 -0500
Re: Double integer input Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-23 14:58 -0600
Re: Double integer input Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-23 22:01 +0100
Re: Double integer input albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-02-24 04:03 +0000
Re: Double integer input "Elizabeth D. Rather" <erather@forth.com> - 2013-02-23 18:13 -1000
Re: Double integer input Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-02-24 12:01 +0100
Re: Double integer input anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-25 18:09 +0000
Re: Double integer input rickman <gnuarm@gmail.com> - 2013-02-24 15:01 -0500
Re: Double integer input Coos Haak <chforth@hccnet.nl> - 2013-02-25 01:13 +0100
Re: Double integer input Mark Wills <markrobertwills@yahoo.co.uk> - 2013-02-24 23:44 -0800
Re: Double integer input rickman <gnuarm@gmail.com> - 2013-02-27 07:47 -0500
Re: Double integer input Mark Wills <markrobertwills@yahoo.co.uk> - 2013-02-24 23:42 -0800
Re: Double integer input Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-25 03:57 -0600
Re: Double integer input albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-02-25 14:09 +0000
Re: Double integer input Bernd Paysan <bernd.paysan@gmx.de> - 2013-02-25 16:45 +0100
Re: Double integer input Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-25 18:26 -0600
Re: Double integer input Bernd Paysan <bernd.paysan@gmx.de> - 2013-02-26 02:04 +0100
Re: Double integer input Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-26 05:10 -0600
Re: Double integer input Bernd Paysan <bernd.paysan@gmx.de> - 2013-02-26 15:31 +0100
Re: Double integer input Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-26 10:28 -0600
Re: Double integer input anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-25 16:38 +0000
Re: Double integer input rickman <gnuarm@gmail.com> - 2013-02-24 14:54 -0500
Re: Double integer input "Elizabeth D. Rather" <erather@forth.com> - 2013-02-24 11:59 -1000
Re: Double integer input anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-25 18:11 +0000
Re: Double integer input rickman <gnuarm@gmail.com> - 2013-02-27 07:58 -0500
Re: Double integer input anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-03-02 17:10 +0000
Re: Double integer input "Ed" <invalid@nospam.com> - 2013-02-22 13:22 +1100
Re: Double integer input "Elizabeth D. Rather" <erather@forth.com> - 2013-02-21 16:31 -1000
Re: Double integer input Alex McDonald <blog@rivadpm.com> - 2013-02-22 04:54 -0800
Re: Double integer input "WJ" <w_a_x_man@yahoo.com> - 2013-02-24 22:05 +0000
Re: Double integer input Paul Rubin <no.email@nospam.invalid> - 2013-02-24 15:02 -0800
Re: Double integer input Brad Eckert <hwfwguy@gmail.com> - 2013-02-25 09:22 -0800
Re: Double integer input Brad Eckert <hwfwguy@gmail.com> - 2013-02-25 10:21 -0800
Re: Double integer input Alex McDonald <blog@rivadpm.com> - 2013-02-26 07:47 -0800
Re: Double integer input "WJ" <w_a_x_man@yahoo.com> - 2013-02-28 06:27 +0000
Re: Double integer input Paul Rubin <no.email@nospam.invalid> - 2013-02-23 21:34 -0800
Re: Double integer input "Elizabeth D. Rather" <erather@forth.com> - 2013-02-24 08:16 -1000
csiph-web