Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > decrease MAC

Reply
Thread Tools

decrease MAC

 
 
jammer
Guest
Posts: n/a
 
      03-17-2008
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?
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      03-17-2008

Quoth jammer <(E-Mail Removed)>:
> 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

 
Reply With Quote
 
 
 
 
jammer
Guest
Posts: n/a
 
      03-17-2008
On Mar 17, 4:06 pm, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth jammer <(E-Mail Removed)>:
>
> > 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
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      03-17-2008
jammer <(E-Mail Removed)> 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
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      03-17-2008

Quoth Tad J McClellan <(E-Mail Removed)>:
> jammer <(E-Mail Removed)> 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

 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      03-17-2008
jammer <(E-Mail Removed)> wrote:
>On Mar 17, 4:06 pm, Ben Morrow <(E-Mail Removed)> wrote:
>> Quoth jammer <(E-Mail Removed)>:
>> > 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
 
Reply With Quote
 
Josef Moellers
Guest
Posts: n/a
 
      03-18-2008
jammer wrote:
> On Mar 17, 4:06 pm, Ben Morrow <(E-Mail Removed)> wrote:
>> Quoth jammer <(E-Mail Removed)>:
>>
>>> 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
 
Reply With Quote
 
jammer
Guest
Posts: n/a
 
      03-18-2008
On Mar 18, 5:29 am, Josef Moellers <josef.moell...@fujitsu-
siemens.com> wrote:
> jammer wrote:
> > On Mar 17, 4:06 pm, Ben Morrow <(E-Mail Removed)> wrote:
> >> Quoth jammer <(E-Mail Removed)>:

>
> >>> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I decrease first page load time when there are 300 dll's on bin folder? Ravi Ambros Wallau ASP .Net 1 02-14-2006 09:06 PM
Massive TTL Decrease ISAKMP-IPSEC VPN Joel Salminen Cisco 1 01-20-2006 05:33 AM
XML for summies... how to edit to decrease size of 100 pages? Clarence XML 3 08-11-2005 08:55 AM
Performance decrease after migration to .NET Christian Correa ASP .Net 0 12-01-2004 03:15 AM
How do I decrease spacing in between elements (there are no <br> codes to delete)? fitwell HTML 7 11-19-2003 08:25 PM



Advertisments