Skip to content

Instantly share code, notes, and snippets.

@xardit
Created May 25, 2016 20:53
Show Gist options
  • Save xardit/121330211ef8eac9d7b1e4cfbc0a3837 to your computer and use it in GitHub Desktop.
Save xardit/121330211ef8eac9d7b1e4cfbc0a3837 to your computer and use it in GitHub Desktop.
function bin2all() {
if [[ $1 ]]; then
echo "Binary $1 = Octal $(bin2oct $1)"
echo "Binary $1 = Decimal $(bin2dec $1)"
echo "Binary $1 = Hexadecimal $(bin2hex $1)"
echo "Binary $1 = Base32 $(bin2base32 $1)"
echo "Binary $1 = Base64 $(bin2base64 $1)"
echo "Binary $1 = ASCII $(bin2ascii $1)"
else
echo "Convert Binary numbers to all representations"
echo "Usage: bin2all [Binary numbers]"
fi
}
function bin2oct() {
if [[ $1 ]]; then
echo "obase=8 ; ibase=2 ; $1" | bc
else
echo "Convert Binary numbers to Octal"
echo "Usage: bin2oct [Binary numbers]"
fi
}
function bin2dec() {
if [[ $1 ]]; then
echo $((2#$1))
else
echo "Convert Binary numbers to Decimal"
echo "Usage: bin2dec [Binary numbers]"
fi
}
function bin2hex() {
if [[ $1 ]]; then
echo "obase=16 ; ibase=2 ; $1" | bc
else
echo "Convert Binary numbers to Hexadecimal"
echo "Usage: bin2hex [Binary numbers]"
fi
}
function bin2base32() {
if [[ $1 ]]; then
echo "obase=32 ; ibase=2 ; $1 " | bc
else
echo "Convert Binary numbers to Base32"
echo "Usage: bin2base32 [Binary numbers]"
fi
}
function bin2base64() {
if [[ $1 ]]; then
echo "obase=64 ; ibase=2 ; $1" | bc
else
echo "Convert Binary numbers to Base64"
echo "Usage: bin2base64 [Binary numbers]"
fi
}
function bin2ascii() {
if [[ $1 ]]; then
echo -e "\0$(printf %o $((2#$1)))"
else
echo "Convert Binary numbers to ASCII characters"
echo "Usage: bin2acii [Binary numbers]"
fi
}
function oct2all() {
if [[ $1 ]]; then
echo "Octal $1 = Binary $(oct2bin $1)"
echo "Octal $1 = Decimal $(oct2dec $1)"
echo "Octal $1 = Hexadecimal $(oct2hex $1)"
echo "Octal $1 = Base32 $(oct2base32 $1)"
echo "Octal $1 = Base64 $(oct2base64 $1)"
echo "Octal $1 = ASCII $(oct2ascii $1)"
else
echo "Convert Octal numbers to all representations"
echo "Usage: oct2all [Octal numbers]"
fi
}
function oct2bin() {
if [[ $1 ]]; then
echo "obase=2 ; ibase=8 ; $1" | bc
else
echo "Convert Octal numbers to Binary"
echo "Usage: oct2bin [Octal numbers]"
fi
}
function oct2dec() {
if [[ $1 ]]; then
echo $((8#$1))
else
echo "Convert Octal numbers to Decimal"
echo "Usage: oct2dec [Octal numbers]"
fi
}
function oct2hex() {
if [[ $1 ]]; then
echo "obase=16 ; ibase=8 ; $1" | bc
else
echo "Convert Octal numbers to Hexadecimal"
echo "Usage: oct2hex [Octal numbers]"
fi
}
function oct2base32() {
if [[ $1 ]]; then
echo "obase=32 ; ibase=8 ; $1" | bc
else
echo "Convert Octal numbers to Base32"
echo "Usage: oct2base32 [Octal numbers]"
fi
}
function oct2base64() {
if [[ $1 ]]; then
echo "obase=64 ; ibase=8 ; $1" | bc
else
echo "Convert Octal numbers to Base64"
echo "Usage: oct2base64 [Octal numbers]"
fi
}
function oct2ascii() {
if [[ $1 ]]; then
echo -e "\0$(printf %o $((8#$1)))"
else
echo "Convert Octal numbers to ASCII characters"
echo "Usage: oct2ascii [Octal numbers]"
fi
}
function dec2all() {
if [[ $1 ]]; then
echo "Decimal $1 = Binary $(dec2bin $1)"
echo "Decimal $1 = Octal $(dec2oct $1)"
echo "Decimal $1 = Hexadecimal $(dec2hex $1)"
echo "Decimal $1 = Base32 $(dec2base32 $1)"
echo "Decimal $1 = Base64 $(dec2base64 $1)"
echo "Decimal $1 = ASCII $(dec2ascii $1)"
else
echo "Convert Decimal numbers to all representations"
echo "Usage: dec2all [Decimal numbers]"
fi
}
function dec2bin() {
if [[ $1 ]]; then
echo "obase=2 ; $1" | bc
else
echo "Convert Decimal numbers to Binary"
echo "Usage: dec2bin [Decimal numbers]"
fi
}
function dec2oct() {
if [[ $1 ]]; then
echo "obase=8 ; $1" | bc
else
echo "Convert Decimal numbers to Octal"
echo "Usage: dec2oct [Decimal numbers]"
fi
}
function dec2hex() {
if [[ $1 ]]; then
echo "obase=16 ; $1" | bc
else
echo "Convert Decimal numbers to Hexadecimal"
echo "Usage: dec2hex [Decimal numbers]"
fi
}
function dec2base32() {
if [[ $1 ]]; then
echo "obase=32 ; $1" | bc
else
echo "Convert Decimal numbers to Base32"
echo "Usage: dec2base32 [Decimal numbers]"
fi
}
function dec2base64() {
if [[ $1 ]]; then
echo "obase=64 ; $1" | bc
else
echo "Convert Decimal numbers to Base64"
echo "Usage: dec2base64 [Decimal numbers]"
fi
}
function dec2ascii() {
if [[ $1 ]]; then
echo -e "\0$(printf %o 97)"
else
echo "Convert Decimal numbers to ASCI characters"
echo "Usage: dec2ascii [Decimal numbers]"
fi
}
function hex2all() {
if [[ $1 ]]; then
echo "Hexadecimal $1 = Binary $(hex2bin $1)"
echo "Hexadecimal $1 = Octal $(hex2oct $1)"
echo "Hexadecimal $1 = Decimal $(hex2dec $1)"
echo "Hexadecimal $1 = Base32 $(hex2base32 $1)"
echo "Hexadecimal $1 = Base64 $(hex2base64 $1)"
echo "Hexadecimal $1 = ASCII $(hex2ascii $1)"
else
echo "Convert Hexadecimal numbers to all representations"
echo "Usage: hex2all [Hexadecimal numbers]"
fi
}
function hex2bin() {
if [[ $1 ]]; then
echo "obase=2 ; ibase=16 ; $1" | bc
else
echo "Convert Hexadecimal numbers to Binary"
echo "Usage: hex2bin [Hexadecimal numbers]"
fi
}
function hex2oct() {
if [[ $1 ]]; then
echo "obase=8 ; ibase=16 ; $1" | bc
else
echo "Convert Hexadecimal numbers to Octal"
echo "Usage: hex2oct [Hexadecimal numbers]"
fi
}
function hex2dec() {
if [[ $1 ]]; then
echo $((16#$1))
else
echo "Convert Hexadecimal numbers to Decimal"
echo "Usage: hex2dec [Hexadecimal numbers]"
fi
}
function hex2base32() {
if [[ $1 ]]; then
echo "obase=32 ; ibase=16 ; $1" | bc
else
echo "Convert Hexadecimal numbers to Base32"
echo "Usage: hex2base32 [Hexadecimal numbers]"
fi
}
function hex2base64() {
if [[ $1 ]]; then
echo "obase=64 ; ibase=16 ; $1" | bc
else
echo "Convert Hexadecimal numbers to Base64"
echo "Usage: hex2base64 [Hexadecimal numbers]"
fi
}
function hex2ascii() {
if [[ $1 ]]; then
echo -e "\0$(printf %o $((16#$1)))"
else
echo "Convert Hexadecimal numbers to ASCII characters"
echo "Usage: hex2ascii [Hexadecimal numbers]"
fi
}
function ascii2all() {
if [[ $1 ]]; then
echo "ASCII $1 = Binary $(ascii2bin $1)"
echo "ASCII $1 = Octal $(ascii2oct $1)"
echo "ASCII $1 = Decimal $(ascii2dec $1)"
echo "ASCII $1 = Hexadecimal $(ascii2hex $1)"
echo "ASCII $1 = Base32 $(ascii2base32 $1)"
echo "ASCII $1 = Base64 $(ascii2base64 $1)"
else
echo "Convert ASCII characters to all representations"
echo "Usage: ascii2all [ASCII characters]"
fi
}
function ascii2bin() {
if [[ $1 ]]; then
echo "obase=2 ; $(ascii2dec $1)" | bc
else
echo "Convert ASCII characters to Binary"
echo "Usage: ascii2bin [ASCII characters]"
fi
}
function ascii2oct() {
if [[ $1 ]]; then
echo "obase=8 ; $(ascii2dec $1)" | bc
else
echo "Convert ASCII characters to Octal"
echo "Usage: ascii2oct [ASCII characters]"
fi
}
function ascii2dec() {
if [[ $1 ]]; then
printf '%d\n' "'$1'"
else
echo "Convert ASCII characters to Decimal"
echo "Usage: ascii2dec [ASCII characters]"
fi
}
function ascii2hex() {
if [[ $1 ]]; then
echo "obase=16 ; $(ascii2dec $1)" | bc
else
echo "Convert ASCII characters to Hexadecimal"
echo "Usage: ascii2hex [ASCII characters]"
fi
}
function ascii2base32() {
if [[ $1 ]]; then
echo "obase=32 ; $(ascii2dec $1)" | bc
else
echo "Convert ASCII characters to Base32"
echo "Usage: ascii2base32 [ASCII characters]"
fi
}
function ascii2base64() {
if [[ $1 ]]; then
echo "obase=64 ; $(ascii2dec $1)" | bc
else
echo "Convert ASCII characters to Base64"
echo "Usage: ascii2base64 [ASCII characters]"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment