decrease MAC

Discussion in 'Perl Misc' started by jammer, Mar 17, 2008.

  1. jammer

    jammer Guest

    I have a hex number which is actually a MAC address and I want to find
    the MAC immediately before.
    0000AAAA9999

    Is there a way to treat it as a hex number and do -1 one on it?
    jammer, Mar 17, 2008
    #1
    1. Advertising

  2. jammer

    Ben Morrow Guest

    Quoth jammer <>:
    > I have a hex number which is actually a MAC address and I want to find
    > the MAC immediately before.
    > 0000AAAA9999
    >
    > Is there a way to treat it as a hex number and do -1 one on it?


    my $MAC = '0000AAAA9999';
    printf "%x\n", hex($MAC) - 1;

    Ben
    Ben Morrow, Mar 17, 2008
    #2
    1. Advertising

  3. jammer

    jammer Guest

    On Mar 17, 4:06 pm, Ben Morrow <> wrote:
    > Quoth jammer <>:
    >
    > > I have a hex number which is actually a MAC address and I want to find
    > > the MAC immediately before.
    > > 0000AAAA9999

    >
    > > Is there a way to treat it as a hex number and do -1 one on it?

    >
    > my $MAC = '0000AAAA9999';
    > printf "%x\n", hex($MAC) - 1;
    >
    > Ben


    What if there are not 4 leading 0s.
    my $MAC = '000BAAAA9999';
    printf "%x\n", hex($MAC) - 1;
    Integer overflow in hexadecimal number
    jammer, Mar 17, 2008
    #3
  4. jammer <> wrote:
    >I have a hex number which is actually a MAC address and I want to find
    >the MAC immediately before.
    >0000AAAA9999
    >
    >Is there a way to treat it as a hex number and do -1 one on it?


    "God made the natural numbers, all else is men's work"
    There is no such thing as a hex(adezimal) number. You got numbers and that
    is what Perl knows about and where you can add and subtract and do other
    fancy stuff with.

    And then you can input as well as print those numbers in different
    representations, e.g. as a hexadecimal representation of a number.
    - to convert the hex representation of a number into a number use hex()
    - to print the hexadezimal representation of a number use printf

    jue
    Jürgen Exner, Mar 17, 2008
    #4
  5. jammer

    Ben Morrow Guest

    Quoth Tad J McClellan <>:
    > jammer <> wrote:
    >
    > > my $MAC = '000BAAAA9999';

    >
    > What _is_ significant is the number of bits required to represent the number.
    >
    > ie. 32 bits required for Ben's number, but 36 bits are required
    > for your number.
    >
    > > printf "%x\n", hex($MAC) - 1;
    > > Integer overflow in hexadecimal number

    >
    > What do you know?
    >
    > The message is exactly right, assuming you are on a 32-bit processor. :)


    And there are two solutions: use a perl built for 64-bit integers
    (practically every processor nowadays has a 64-bit integral type, and
    perl can usually use these if asked to); or use 'bigint', which will
    allow arbitrary-sized integers at the expense of some speed.

    Ben
    Ben Morrow, Mar 17, 2008
    #5
  6. jammer <> wrote:
    >On Mar 17, 4:06 pm, Ben Morrow <> wrote:
    >> Quoth jammer <>:
    >> > 0000AAAA9999
    >> > Is there a way to treat it as a hex number and do -1 one on it?

    >>
    >> my $MAC = '0000AAAA9999';
    >> printf "%x\n", hex($MAC) - 1;

    >
    >What if there are not 4 leading 0s.


    So what? Doesn't matter.

    >my $MAC = '000BAAAA9999';
    >printf "%x\n", hex($MAC) - 1;
    >Integer overflow in hexadecimal number


    That error message simply indicates that the numerical value exceeds the
    largest possible number in this version of the perl interpreter.
    What is the output of 'perl -V' on your system?

    Maybe the bigint module will help on systems with a low maxint, but that is
    just a guess.

    jue
    Jürgen Exner, Mar 17, 2008
    #6
  7. jammer wrote:
    > On Mar 17, 4:06 pm, Ben Morrow <> wrote:
    >> Quoth jammer <>:
    >>
    >>> I have a hex number which is actually a MAC address and I want to find
    >>> the MAC immediately before.
    >>> 0000AAAA9999
    >>> Is there a way to treat it as a hex number and do -1 one on it?

    >> my $MAC = '0000AAAA9999';
    >> printf "%x\n", hex($MAC) - 1;
    >>
    >> Ben

    >
    > What if there are not 4 leading 0s.
    > my $MAC = '000BAAAA9999';
    > printf "%x\n", hex($MAC) - 1;
    > Integer overflow in hexadecimal number


    Pragmatic approach: split up into smaller parts, do the math, then
    re-assemble.

    --
    These are my personal views and not those of Fujitsu Siemens Computers!
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html
    Josef Moellers, Mar 18, 2008
    #7
  8. jammer

    jammer Guest

    On Mar 18, 5:29 am, Josef Moellers <josef.moell...@fujitsu-
    siemens.com> wrote:
    > jammer wrote:
    > > On Mar 17, 4:06 pm, Ben Morrow <> wrote:
    > >> Quoth jammer <>:

    >
    > >>> I have a hex number which is actually a MAC address and I want to find
    > >>> the MAC immediately before.
    > >>> 0000AAAA9999
    > >>> Is there a way to treat it as a hex number and do -1 one on it?
    > >> my $MAC = '0000AAAA9999';
    > >> printf "%x\n", hex($MAC) - 1;

    >
    > >> Ben

    >
    > > What if there are not 4 leading 0s.
    > > my $MAC = '000BAAAA9999';
    > > printf "%x\n", hex($MAC) - 1;
    > > Integer overflow in hexadecimal number

    >
    > Pragmatic approach: split up into smaller parts, do the math, then
    > re-assemble.
    >

    Good idea. :)
    jammer, Mar 18, 2008
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian Correa

    Performance decrease after migration to .NET

    Christian Correa, Dec 1, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    350
    Christian Correa
    Dec 1, 2004
  2. Ravi Ambros Wallau
    Replies:
    1
    Views:
    508
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 14, 2006
  3. fitwell
    Replies:
    7
    Views:
    747
    Sid Ismail
    Nov 19, 2003
  4. Clarence
    Replies:
    3
    Views:
    409
    Joris Gillis
    Aug 11, 2005
  5. Filipe Martins

    A way to decrease executable sizes?

    Filipe Martins, Apr 15, 2004, in forum: C++
    Replies:
    17
    Views:
    854
    Peter van Merkerk
    Apr 15, 2004
Loading...

Share This Page