Let's say I have the bitmask 1000000000
. I would like to convert it to its equivalent hexadecimal number, i.e. 0x200
(specifically, I only want the 200
part, but that's easy to take care of)
I know I can do this in Python or using various bash
features and functions. Examples:
python -c "print format(0b1000000000, 'x')"
200
printf '%x\n' "$((2#1000000000))"
200
echo 'ibase=2;obase=10000;1000000000'|bc
200
But, I wanna do this using only functions available in sh
(i.e. Shell, not Bash). More specifically, I want it to work with sh
in an initrd
image that I'm putting together. AFAIK, none of the examples above would work in an initramfs
/ busybox
context.