CONVERSIONS FROM ONE NUMBER SYSTEM TO ANOTHER

decimal to binary


code

D2B=({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1})
echo ${D2B[85]}

output:

01010101

octal to binary


code:

perl -e 'printf "%b\n",'0304

output:

83

hexadecimal to binary


code:

echo "obase=2; ibase=16; DEAD" | bc

output:

1101111010101101

binary to decimal


code

$ echo "$((2#101010101))"

output:

341

binary to octal


code:

echo "obase=8; ibase=2; 110101100010" | bc

output:

6542

binary to hexadecimal


code:

echo "obase=16; ibase=2; 110010010111" | bc

output:

C97

  1. https://stackoverflow.com/questions/10278513/bash-shell-decimal-to-binary-base-2-conversion

  2. https://stackoverflow.com/questions/73889269/convert-binary-octal-decimal-and-hexadecimal-values-between-each-other-in-bash

  3. https://unix.stackexchange.com/questions/65280/binary-to-hexadecimal-and-decimal-in-a-shell-script