Loading ...
Sorry, an error occurred while loading the content.

Need help with doing a procedure in reverse

Expand Messages
  • Bobby Jafari
    Hi All, I have the following procedure: $MAC = 00:11:22:33:44:55 ; @MAC = split /:/, $MAC; $hexMAC = ; foreach (@MAC) { $hexMAC = $hexMAC.chr(hex($_));
    Message 1 of 3 , Oct 1, 2006
    • 0 Attachment
      Hi All,

      I have the following procedure:

      $MAC = "00:11:22:33:44:55";
      @MAC = split /:/, $MAC;
      $hexMAC = "";
      foreach (@MAC) { $hexMAC = $hexMAC.chr(hex($_));
      print "hexMAC is $hexMAC\n";

      I think the print will produce some character that is the ASCI
      representation of the hex number.

      Knowing the above, you have $hexMAC and want to get to a colon separated
      MAC address. How is this done.
      Regards,
      Bobby


      [Non-text portions of this message have been removed]
    • Charles K. Clarkson
      ... IF it worked, I think it will print the native 8-bit encoding for your machine, which is most likely ASCII, but not necessarily. ... ord() is basically the
      Message 2 of 3 , Oct 1, 2006
      • 0 Attachment
        Bobby Jafari wrote:

        : I think the print will produce some character that is
        : the ASCI representation of the hex number.

        IF it worked, I think it will print the native 8-bit
        encoding for your machine, which is most likely ASCII, but
        not necessarily.


        : Knowing the above, you have $hexMAC and want to get to a
        : colon separated MAC address. How is this done.

        ord() is basically the reverse of chr(). You could use
        sprintf() to format a decimal value into a hexadecimal value.
        See perlfaq4: How do I convert between numeric
        representations/bases/radixes?

        Joining these values into a colon denominated string
        shouldn't present too tough a problem. To split a string
        into two character sections you might use this.

        my @machine = $hexMAC =~ /(..)/g;


        HTH,

        Charles K. Clarkson
        --
        Mobile Homes Specialist
        Free Market Advocate
        Web Programmer

        254 968-8328

        Don't tread on my bandwidth. Trim your posts.
      • Bobby Jafari
        ... sprintf ( %.2d:%.2d ,ord(substr($hexMAC},0,1)),ord(substr($hexMAC,1,1)));
        Message 3 of 3 , Oct 2, 2006
        • 0 Attachment
          > ord() is basically the reverse of chr(). You could use
          > sprintf() to format a decimal value into a hexadecimal value.
          > See perlfaq4: How do I convert between numeric
          > representations/bases/radixes?

          > Joining these values into a colon denominated string
          > shouldn't present too tough a problem. To split a string
          > into two character sections you might use this.

          > my @machine = $hexMAC =~ /(..)/g;

          sprintf
          ("%.2d:%.2d",ord(substr($hexMAC},0,1)),ord(substr($hexMAC,1,1)));
        Your message has been successfully submitted and would be delivered to recipients shortly.