Bash

Convert between numerical bases

#!/bin/bash                                                
printf "hex2dec=";echo "ibase=16;$1"|bc                         
printf "dec2hex=";echo "obase=16;$1"|bc                         
printf "oct2dec=";echo "ibase=8;$1"|bc                          
printf "dec2oct=";echo "obase=8;$1"|bc


Binary to decimal

 

#! /bin/bash
D2B=({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1})
echo $((10#${D2B[$1]}))

 

About Linuxgal

Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s