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