I have a file containing a list of hexadecimal numbers, as
0x12345678 one per line.
I want to make a calculation on them. For this, I thought of using
awk . But if printing an hexadecimal number with awk is easy with the printf function, I haven't find a way to interpret the hexadecimal input other than as text (or 0 , conversion to integer stops on the x ).
Is it possible to print, e.g. the value +1?
Edit: One liners on other languages welcomed! (if reasonable length ;-) )
| ||||
feedback
|
3
|
In the original
nawk and mawk implementations the hexadecimal (and octal) numbers are recognised.gawk (which I guess you are using) has the feature/bug of not doing this. It has a command line switch to get the behaviour you want: --non-decimal-data .
| ||
feedback
|
1
|
gawk has the
strtonum function:
| ||
feedback
|
0
|
You can convert the string into a number, simply by doing
$1 + 0 . AWK automagically converts a string to a number as needed. So you can do:
or if you want
0x1234 notation:
| ||
Was this post useful to you?
|
'via Blog this'