Hacker News new | ask | show | jobs
by binaryapparatus 2717 days ago

    function convert-decimaltobinary(){
        n="$1"
        bit=""
        while [ "$n" -gt 0 ]; do
            bit="$(( n&1 ))$bit";
            : $(( n >>= 1 ))
        done
        printf "%s\n" "$bit"
    }
    function convert-binarytodecimal(){
        echo "$((2#$1))"
    }
    function convert-hextodecimal(){
        echo $(( 16#$1 ))
    }
1 comments

I think I'll use them more if they're cdb, cbd, chd. Thanks!