Discussion:
Hex 2 dec conversion
(too old to reply)
Robert Vanpass
2019-12-11 18:43:42 UTC
Permalink
Hi,

I have a .csv datafile with only 2-digit numbers in Hexadecimal form:
6F
73
A5
...

Is there a function in Gnuplot to convert these Hex numbers to Decimal form,
or should it be written / how ?
Another possibility would be to use an external commandline converter, something like Grepwin.
Any idea what I could use for this ?

Thanks
Robert Vanpass
2019-12-11 18:46:51 UTC
Permalink
Post by Robert Vanpass
Hi,
6F
73
A5
...
Is there a function in Gnuplot to convert these Hex numbers to Decimal form,
or should it be written / how ?
Another possibility would be to use an external commandline converter, something like Grepwin.
Any idea what I could use for this ?
(I use Gnuplot 5.2.2 with Windows 10).
Thanks
Hans-Bernhard Bröker
2019-12-11 22:40:17 UTC
Permalink
Post by Robert Vanpass
Hi,
6F
73
A5
...
That has surprisingly few commas and semicolons for a csv file :-)
Post by Robert Vanpass
Is there a function in Gnuplot to convert these Hex numbers to Decimal form,
No.

There's the "send the data through an external program before use"
function, but that's not terribly useful if you know no external program
to do that kind of transformation job for you.

In the Unix environment gnuplot originally grew up in, it would work
roughly like this:

plot "< awk -e '{printf \"%d\", strtonum (\"0x\" $1)) }' yourfile.csv"

If you do have an 'awk' command around, that should actually work even
on Windows.

OTOH, if it's actual CSV and you're on Windows, you might want to follow
the saying "when in Rome, do as the Romans" and just perform the
transformation in you preferred spreadsheet program...
Karl Ratzsch
2019-12-12 21:10:49 UTC
Permalink
Post by Robert Vanpass
Is there a function in Gnuplot to convert these Hex numbers to Decimal form,
No.
Actually yes. Gnuplot understands hexadecimal (and octal), the
number just needs a preceeding "0x" (or "0") marker. You just have
to add it in your "using" statement, and then take advantage of
gnuplot´s automatic type promotion:

$dat << EOD
11c 4
12a 5
133 4
13f 6
1aa 1
EOD

pl $dat us (("0x".strcol(1))*1):2 w l

Admittedly, I was very doubtful too before seeing the above example
actually producing a plot. ;)
Robert Vanpass
2019-12-14 19:28:46 UTC
Permalink
Post by Robert Vanpass
Hi,
6F
73
A5
...
Is there a function in Gnuplot to convert these Hex numbers to Decimal form,
or should it be written / how ?
Another possibility would be to use an external commandline converter, something like Grepwin.
Any idea what I could use for this ?
Thanks
This works perfectly.

Thank you so much !
Robert Vanpass
2019-12-15 07:19:39 UTC
Permalink
Post by Robert Vanpass
Hi,
6F
73
A5
...
Is there a function in Gnuplot to convert these Hex numbers to Decimal form,
or should it be written / how ?
Another possibility would be to use an external commandline converter, something like Grepwin.
Any idea what I could use for this ?
Thanks
Actually this is very intriguing to me:

I tried to find this info myself in
- the basic Gnuplot reference (Gnuplot helpfiles)
- Gnuplot in action (Philipp K. Janert)
- Gnuplot cookbook (Lee Phillips)
but couldn't find anything like that.

Where else could I look to learn tings like this ?
(From time to time I'm really stuck, so you might see more posts from me...)

Thanks

Loading...