Converting Hex to Binary is quite easy. You just need paper and a pen. But sometimes you have a sequence of decimal numbers, and you want to calculate their hexadecimal values. bc command is your magic tool. The bc command in Linux is a command-line utility that stands for “basic calculator”. It provides a simple way to perform mathematical calculations within the terminal. Here’s an example of how to use bc command for simple mathematic calculation:

$ echo "2 + 2" | bc
4

We can use the bc command to convert decimal numbers to their hexadecimal equivalent. For example, we can use bc to obtain the hexadecimal values for: [170 187 204 221 238 255]:

$ echo "obase=16; 170;187;204;221;238;255" | bc
AA
BB
CC
DD
EE
FF

You can play with the obase and ibase options. For instance you can convert hexadecimals to decimals like this:

$ echo "ibase=16; AA;BB;CC;DD;EE;FF" | bc
170
187
204
221
238
255

If you want more fun, try this command by yourself:

$ echo "ibase=10;obase=2; 170;187;204;221;238;255" | bc