Check out pack() and unpack() for converting the values.

-----Original Message-----
From: Tim Musson [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 18, 2002 12:15 PM
To: [EMAIL PROTECTED]
Subject: Bit reversal of MAC Address bytes...


hey perl guru's,

  I have need to do a bit reversal of a MAC address (some Token Ring to
  Ethernet thing) and am stumped.

  Cisco has an app on their web site if you can log in, but not
  everyone can log in, and I am not always attached...

  So I was thinking I would build one myself, but not sure how to
  proceed...

  The interface and all that I can do, but...

  Input : 4000 0000 0001
  Output: 2000 0000 0008

  The way it is done is to break it into bytes (yes, these are hex)
      40 00 00 00 00 01
  convert into binary (for each byte, but if I have one...)
      40 = 0100 0000
  reverse the order of the bits and convert back to hex
           0000 0010 = 02
  and finally reassemble into the output listed above.

  So, 3 specific questions...

  1. How do I brake the MAC Address up into bytes?

  2. How to convert to binary and put it in a variable?  I think I
  have seen sprintf to convert, but how to get that into the var...

  I think I can do the bit reversal part - I seem to recall seeing
  that type of thing in the Cookbook.

  3. Then how to convert back to hex?

-- 
[EMAIL PROTECTED]
Using The Bat! eMail v1.53d
Windows NT 5.0.2195 (Service Pack 2)
When in doubt, think.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------------------
This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to