+ Reply to Thread
Results 1 to 6 of 6

Excel 2007 : To convert a Perl formula to an Excel formula?

  1. #1
    Registered User
    Join Date
    09-28-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    To convert a Perl formula to an Excel formula?

    Hi, people,

    First... for this problem... some definitions...
    An IP ADDRESS is something like 111.22.33.44.
    An IP NUMBER is the same thing, converted to a sortable number, usually with 10 digits.

    A certain website gives me a bunch of IP Numbers.
    I need to convert them back to IP Addresses.

    The website gives me the PERL formulas...

    To convert an IP address to an IP number...
    ipnum = 16777216*w + 65536*x + 256*y + z
    where
    IP Address = w.x.y.z
    The reverse of this formula is
    w = int ( ipnum / 16777216 ) % 256;
    x = int ( ipnum / 65536 ) % 256;
    y = int ( ipnum / 256 ) % 256;
    z = int ( ipnum ) % 256;
    Where % is the mod operator.

    and

    To convert an IP number to an IP address...
    sub numToStr {
    my ($ipnum) = @_;
    my $z = $ipnum % 256;
    $ipnum >>= 8;
    my $y = $ipnum % 256;
    $ipnum >>= 8;
    my $x = $ipnum % 256;
    $ipnum >>= 8;
    my $w = $ipnum % 256;
    return "$w.$x.$y.$z";
    }

    I don't know Perl, or what "mod operator" means.

    What's the Excel formula that I can put in cell B2...
    to convert the IP Number in A2 to an IP Address?

    Thanks, in advance.

    Mark53

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: To convert a Perl formula to an Excel formula?

    Try

    =INT(A1/256^3) & "." & MOD(INT($A1/256^2), 256) & "." & MOD(INT($A1/256), 256) & "." & MOD($A1, 256)
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    09-28-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: To convert a Perl formula to an Excel formula?

    Wow. That's brilliant, SHG.
    It sure Looks like it worked.
    Now... to Verify... can you please tell me the formula to convert it back?
    Thanks Very Much.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: To convert a Perl formula to an Excel formula?

    If the components are understood to be decimal (not octal)

    =SUMPRODUCT(A1:D1 * 256^{3,2,1,0})

  5. #5
    Registered User
    Join Date
    09-28-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: To convert a Perl formula to an Excel formula?

    Say what?
    I put your first formula in G2, so now G2 looks exactly how I want it... like 111.22.33.44.
    Your formula changed 1234567899 into 111.22.33.44. Terrific.
    So, to verify, what do I put in H2, turning G2 BACK into 1234567899 ?

    Thanks.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: To convert a Perl formula to an Excel formula?

    That would be a messy formula or a simple function:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    In C1,

    =IP2IPNum(B1)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1