Let's say I have two bash variables that contain binary values:
a=0011 # decimal 3 b=1000 # decimal 8
Is there a way I can loop through all the possible values between $a
and $b
keeping it binary? Something like:
for blah in $(seq $a $b) ; do print "Blah is: $blah" done
So it will output:
Blah is: 0011 Blah is: 0100 Blah is: 0101 Blah is: 0110 Blah is: 0111 Blah is: 1000
I have tried:
for blah in $(seq "$((2#$a))" "$((2#$b))") ; do
But then $blah
becomes decimal, and I'd like to keep it a binary (I can always transform the decimal back to binary, but that seems a waste, since I alredy have the extremes in binary)
This code must run in a limited linux (OpenWRT) that doesn't have obase
available. If the answer is that it's not possible to keep the binary value, that's a useful answer as well (I can create a function that converts decimal to binary without using obase
) Besides, it can be a useful answer to people using regular bash
.
dc
command?