What i want is to take an integer represented as a string, for example "1234", and convert it to a file called int, containing a 32-bit big endian integer, with the value 1234.
The only way I have figured out to do this is something like
echo 1234 | awk '{printf "0: %08X", $1}' | xxd -r > int
which is a bit nasty!
Does anyone know a better way?
A slightly simpler way would be:
printf "0: %08X" 1234 | xxd -r > int
ok well seeing that mark williams seems to have gone awol i will post the corrected version of his answer
echo 1234 | perl -e 'print pack("N", <STDIN>); > int
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With