-
-
Save oguz-ismail/a3721dc71723ded5dc7a282367457693 to your computer and use it in GitHub Desktop.
number to binary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LC_ALL=C | |
case $1 in | |
''|[!0-9]*|[!0]*[!0-9]*|0[!0-7Xx]*|0[Xx]|0[!Xx]*[!0-7]*|0[Xx]*[!0-9A-Fa-f]*) | |
printf '%s: invalid number: %s\n' "$0" "$1" >&2 | |
exit 1 | |
esac | |
x=$(($1)) bx= | |
while test $x -gt 0; do | |
bx=$((x & 1))$bx x=$((x >> 1)) | |
done | |
printf '%s\n' ${bx:-0} | |
# vim: ft=sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment