function to_binary () {
    if [ $1 -ge 0 ]
    then
        val=$1
        binary_digits=()

        while [ $val -gt 0 ]; do
            bit=$((val % 2))
            quotient=$((val / 2))
            binary_digits+=("${bit}")
            val=$quotient
        done
        echo "${binary_digits[*]}" | rev
    else
        echo ERROR: "negative number"
        exit 1
    fi
}

array=(5 50 9000)
for number in "${array[@]}"; do
    echo $number ":> " $(to_binary $number)
done