Re: a1.a2.a3.a4 - integer
On Aug 23, P lerenard said: I can transform an ip a1.a2.a3.a4 to an integer using b1=a1 24 b2=a2 16 b3=a3 8 int =b1+b2+b3+a4 now I want to do the opposite. how can I get a1.a2.a3.a4 from this integer? ok I get a1, but I start to have a headeach to get the rest Do: while ($x) { unshift @parts, $x % 256; $x = 8; } and that will give you the parts you need. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: a1.a2.a3.a4 - integer
At 02:08 PM 08/23/01, [EMAIL PROTECTED] wrote: THIS IS NOW THE 5TH REQUEST. TAKE ME OFF THIS ALIAS. That's not very productive for this list. What pard of this link didn't you understand? List-Unsubscribe: mailto:[EMAIL PROTECTED] Sen a blank email there. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: a1.a2.a3.a4 - integer
I think you can get it by shifting the correct number of bits and masking off the lower 8 bits. my $x = $b1+$b2+$b3+$b4; $a4 = $x 0xFF; $a3 = ($x8) 0xFF; $a2 = ($x16) 0xFF; $a1 = ($x24) 0xFF; Good Luck! Tanton -Original Message- From: P lerenard To: [EMAIL PROTECTED] Sent: 8/23/2001 4:01 PM Subject: a1.a2.a3.a4 - integer Hi, I can transform an ip a1.a2.a3.a4 to an integer using b1=a1 24 b2=a2 16 b3=a3 8 int =b1+b2+b3+a4 now I want to do the opposite. how can I get a1.a2.a3.a4 from this integer? ok I get a1, but I start to have a headeach to get the rest Thanks Pierre _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: a1.a2.a3.a4 - integer
On Aug 23, Gibbs Tanton - tgibbs said: $a4 = $x 0xFF; $a3 = ($x8) 0xFF; $a2 = ($x16) 0xFF; $a1 = ($x24) 0xFF; D'oh, I forgot -- is faster than %. while ($x) { unshift @parts, $x 256; $x = 8; } -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: a1.a2.a3.a4 - integer
Hello P, Friday, August 24, 2001, P lerenard [EMAIL PROTECTED] wrote: Pl I can transform an ip a1.a2.a3.a4 to an integer using Pl b1=a1 24 Pl b2=a2 16 Pl b3=a3 8 Pl int =b1+b2+b3+a4 Pl now I want to do the opposite. Pl how can I get a1.a2.a3.a4 from this integer? Pl ok I get a1, but I start to have a headeach to get the rest if you interested in ip addresses conversions, you can use use Socket; sub ip2ul { return inet_aton($_[0]); } sub ul2ip { return inet_ntoa($_[0]); } or something like this: sub ip2ul { return unpack( 'N', pack( 'C4', split( /\./, shift ) ) ); } sub ul2ip { return join( '.', unpack( 'C4', pack( 'N', shift ) ) ); } (receipts stolen from russian fido7.ru.perl group) Best wishes, Maximmailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]