I have the bash line:
expr substr $SUPERBLOCK 64 8
Which is return to me string line:
00080000
I know that this is, actually, a 0x00080000 in little-endian. Is there a way to create integer-variable from it in bash in big-endian like 0x80000?
I have the bash line:
expr substr $SUPERBLOCK 64 8
Which is return to me string line:
00080000
I know that this is, actually, a 0x00080000 in little-endian. Is there a way to create integer-variable from it in bash in big-endian like 0x80000?
Probably a better way to do this but I've come up with this solution which converts the number to decimal and then back to hex (and manually adds the 0x):
printf '0x%x\n' "$((16#00080000))"
Which you could write as:
printf '0x%x\n' "$((16#$(expr substr "$SUPERBLOCK" 64 8)))"
There are two more or less standard (and ancient) command-line unix tools that offer very easy ways to convert numbers between different bases:
$ { echo '16'; echo i; echo 00080000; echo p; } | dc
524288
$ { echo 'ibase=16'; echo 00080000; } | bc
524288
For normal human use I very much prefer bc, but when writing a program that generates code, especially from a parser of some sort, a stack-based tool like dc may be easier to deal with (and indeed the original version of bc was a front-end parser for dc).