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?
稍微简单一点的方法是:
printf "0: %08X" 1234 | xxd -r > int
好吧,看到马克·威廉姆斯似乎已经走了,我将发布他的答案的更正版本
echo 1234 | perl -e 'print pack("N", <STDIN>); > int
this appears to produce the same output on my system. be sure to check perldoc -f pack
.
echo '1234' | perl -e 'print pack("nn", 0,<STDIN>);' > int
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.