如何对bash中的十六进制数字执行按位运算? [英] How to perform bitwise operations on hexadecimal numbers in bash?
本文介绍了如何对bash中的十六进制数字执行按位运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的bash
脚本中,我有一个包含十六进制数字的字符串,例如hex="0x12345678"
.是否可以将其视为十六进制数字并对其进行位移?
In my bash
script I have a string containing a hexadecimal number, e.g. hex="0x12345678"
. Is it possible to treat it as a hex number and do bit shifting on it?
推荐答案
您可以在算术上下文中轻松对这些数字进行位移位:
You can easily bitshift such numbers in an arithmetic context:
$ hex="0x12345678"
$ result=$((hex << 1))
$ printf "Result in hex notation: 0x%x\n" "$result"
0x2468acf0
这篇关于如何对bash中的十六进制数字执行按位运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文