Write a Shell Bash Script for convert Decimal Number to Binary
#!/usr/bin/env bash | |
for ((i = 32; i >= 0; i--)); do | |
r=$((2 ** i)) | |
Probablity+=($r) | |
done | |
[[ $# -eq 0 ]] && { | |
echo -e "Usage \n \t $0 numbers" | |
exit 1 | |
} | |
echo -en "Decimal\t\tBinary\n" | |
for input_int; do | |
s=0 | |
test ${#input_int} -gt 11 && { | |
echo "Support Upto 10 Digit number :: skiping \"$input_int\"" | |
continue | |
} | |
printf "%-10s\t" "$input_int" | |
for n in ${Probablity[@]}; do | |
if [[ $input_int -lt $n ]]; then | |
[[ $s == 1 ]] && printf "%d" 0 | |
else | |
echo -n 1 | |
s=1 | |
input_int=$((input_int - n)) | |
fi | |
done | |
echo -e | |
done |
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND