Click here to get back home

decrease MAC

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
decrease MAC jammer 03-17-2008
Posted by jammer on March 17, 2008, 4:00 pm
Please log in for more thread options
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?

Posted by Ben Morrow on March 17, 2008, 4:06 pm
Please log in for more thread options

> 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


Posted by jammer on March 17, 2008, 4:37 pm
Please log in for more thread options
>
> > 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

Posted by Tad J McClellan on March 17, 2008, 7:38 pm
Please log in for more thread options
>>
>> > 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.


You have completely missed the cause of the effect.


> 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. :-)


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Posted by Ben Morrow on March 17, 2008, 7:36 pm
Please log in for more thread options

>
> > 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


Similar ThreadsPosted
deleteing records from DB_File doesnt decrease file size? September 15, 2006, 7:31 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap