[mrtg] Re: Conversion code for hex to integer
Bill Wichers
billw at waveform.net
Wed Oct 20 05:06:06 MEST 2004
> Greetings list,
>
> My device returns an octet string for a query. To convert this hex value
> to an integer I'm trying a ConversionCode subroutine which I've gleaned
> from this list's archives. But every time the error is returned: "Illegal
> hexadecimal digit".
>
> Could it be that I need to strip off unnecessary characters passed by
> SNMP? When I GET any of several similar OIDs, the returned result is
> always prefixed by the bytes "04 05", followed by five more octets of hex
> data. Here's the value returned from the OID representing an HTTP proxy
> cache's "Total amount of object data transfered to browsers in Kbytes":
>
> 40.05.D6.DC.20.DE.0D
[snip]
Chances are the 40.05 is just not changing much since it's a high value.
For example, if you have a counter of 1,000,000,000 bytes, and you don't
move a large amount of traffic, you maybe have values of 1,000,123,546 and
1,007,546,888 -- the first "1,00" doesn't change much if the counter is
only incrementing by the number of bytes since the last sample (rather
than continually incrementing). Hopefully that makes sense... Hex numbers
do sometimes start with 0x -- but we're not working in an assembler here
so you probably won't see that in this application.
Your "Illegal hexadecimal digit" is probably the "." between values. Hex
numbers that are *numbers* (not addresses) are normally written without
divisions, for example 001e35ac5f.
> I've never dealt with PERL before. I'm relying on PERL reference web sites
> and mail list archives for everything. I love a challenge : > Next I'll
> want to do math on the returned integer values. Seriously.
Perl is very good at taking files apart at characters you specify. You
need to write something that takes out the "." characters from between the
hex digits. The split function might be a starting point for you. Once you
have the .'s out, combine all the hex digits into a string and then
convert them to decimal. Once you've done the conversion you can easily do
any math you want on them using the standard math functions.
-Bill
*****************************
Waveform Technology
UNIX Systems Administrator
--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive http://www.ee.ethz.ch/~slist/mrtg
FAQ http://faq.mrtg.org Homepage http://www.mrtg.org
WebAdmin http://www.ee.ethz.ch/~slist/lsg2.cgi
More information about the mrtg
mailing list