Wednesday, October 29, 2014

Bash Script - Convert int to binary

There are many ways to convert integer variable to binary. Here is one:
#!/bin/bash
a=65535
out=""
while [ $a -gt 0 ]
do
  b=$(($a%2))
a=$(($a/2))
out="$b$out"
done
echo $out

No comments:

Post a Comment