read while read c s;do for((;c--;c/=2)){ LR s=${_:c&1:1}$s } echo $s done