Conversion of strings of binary digits to a number using Python on the commandline:
binary=00001111
DECIMAL=$(python -c "print int('$BINARY', 2)")
echo $decimal
See the docs for the int function.
Oh, wait, I misread the question, you want to know what converting to binary gets you. Well, that depends on what you mean by "convert to binary". Say I want to store a file with a million integers. The integers will be between 0 and 32,000. If I were to store them as text it would take at best two bytes for each number (single digit number and a separator), at worst six bytes (five digit number and a separator), with an average size of 4.6 bytes per number (see comment for the math). I also would have no easy way of choosing the 15th number. If I were store them as 16bit integers (in binary), every number would take up exactly two bytes and I could find the 15th number by seek
'ing to offset 2*(15-1)
and reading two bytes. Also, when I go to do math on the text based version I (or my language) must first convert the string to a number, whereas the binary version is already a 16bit number.
So, in short, you use binary types to
- save space
- have consistent record sizes
- speed up programs