在 Bash 中对无符号数求负
我有一个数字(十六进制),我想要它的补码。例如,如果 X = 20
我希望 bash 执行否定并返回 Y = ~X = DF
。它不必在 bash 中,但它应该使用一个通用的命令行工具,我可以将其包装到脚本中。另请注意,这些数字应该都是无符号的,我希望它们不会溢出可用的位(例如,20
只会是8位,所以输出应该是8位的补码的)。
我已经尝试使用 bash 和 bc 进行各种操作,但还没有找到正确的组合。有什么想法吗?
(如果有人关心的话,目标是将 IRQ 关联设置到特定 CPU,然后将其他 IRQ 设置到所有其他处理器。)
I have a number (hex) and I want the one's complement of it. For example if X = 20
I want bash to perform a negation and return Y = ~X = DF
. It doesn't have to be in bash, but it should use a common command line tool that I can wrap into a script. Also note that the numbers should all be unsigned and I'd prefer they don't overflow the bits available (e.g., 20
would only be 8 bits, so the output should be the 8-bit one's complement of that).
I've tried various things using bash and bc, but haven't found the right combo. Any ideas?
(If anyone cares, the goal is to set the IRQ affinity to a specific CPU and then set the other IRQs to all other processors.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
16#
告诉 bash 该数字以 16 为基数。The
16#
tells bash that the number is in base 16.啊,我是个白痴。
成功了,或者足够接近成功了。
Ah, I'm an idiot.
Does the trick, or close enough to the trick.