develooper Front page | perl.beginners | Postings from March 2002

Bit reversal of MAC Address bytes...

Thread Next
From:
Tim Musson
Date:
March 18, 2002 12:15
Subject:
Bit reversal of MAC Address bytes...
Message ID:
94537937202.20020318151516@Musson.net
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?

-- 
Tim@Musson.net
Using The Bat! eMail v1.53d
Windows NT 5.0.2195 (Service Pack 2)
When in doubt, think.


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About