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

查看:39
本文介绍了在 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天全站免登陆