在UNIX shell脚本中将十进制转换为十六进制 [英] Convert decimal to hexadecimal in UNIX shell script

查看:275
本文介绍了在UNIX shell脚本中将十进制转换为十六进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在UNIX shell脚本中,我可以使用什么将十进制数转换为十六进制数?我认为od会做到这一点,但它并没有意识到我正在给它的ASCII码表示形式。

In a UNIX shell script, what can I use to convert decimal numbers into hexadecimal? I thought od would do the trick, but it's not realizing I'm feeding it ASCII representations of numbers.

printf?毛!

printf? Gross! Using it for now, but what else is available?

推荐答案

echo "obase=16; 34" | bc

如果您想过滤整个整数文件,每行一个:

If you want to filter a whole file of integers, one per line:

( echo "obase=16" ; cat file_of_integers ) | bc

这篇关于在UNIX shell脚本中将十进制转换为十六进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆