How to convert an IPV4 netmask to CIDR
Convert a decimal number to hexadecimal from Bash
As for the faq with the conversion to binary, also in this we make use of the fantastic bash braces extensions to convert to hexadecimal.
So, always considering the bash faq on the binary we start initially by converting a decimal number between 0 and 255 which corresponds to a hexadecimal digit between 0 and FF:(more…)
Convert a decimal number to binary from Bash
Suppose we are working on a bash script and that for some need, not too difficult from reality, it is essential to have to convert a number or a decimal variable into a binary number.
There are of course several solutions but the one I propose does not make use of external programs but it is bash in all respects.
First we need to know the maximum value of the binary number to be obtained in Bash or in how many bits it can be included.(more…)