Note that if your shell is ksh
or zsh
, you don't need bc
to convert to binary¹.
in ksh/zsh:
$ typeset -i2 num1=10
$ print -- "$num1"
2#1010
$ print -- "${num1#??}"
1010
With zsh
:
$ print -- $(( [##2] num1 ))
1010
(zsh doesn't do split+glob upon parameter expansions or arithmetic expansions, so you don't need to quote them, though quoting won't harm).
With ksh93
:
$ num1=10
$ printf '%..2d\n' "$num1"
1010
With any of those, add > register.txt
to redirect that output into a file (replacing its contents, if any), or >> register.txt
to append it to the file (like tee -a
does; though tee
also writes its input to its stdout).
¹ unless the number doesn't fit in a 64 bit integer
>/dev/null
at the end.num1=10; echo "obase=2;$num1" | bc | tee -a register.txt >/dev/null
num
= 10`, you should leave out the spaces. Also don't ask if someone can help, that can be answered by "yes"/"or" and doesn't solve your real problem.