Binary digits: Difference between revisions
→UNIX Shell: replace bc wrapper (already on page) with native implementation
Antoni Gual (talk | contribs) |
(→UNIX Shell: replace bc wrapper (already on page) with native implementation) |
||
Line 5,505:
0 OK, 0:775</pre>
=={{header|UNIX Shell}}==
Since POSIX does not specify local variables, make use of <code>set</code> for highest portability.
<syntaxhighlight lang="sh">bin() {
set -- "${1:-0}" ""
do
set -- $(($1 >> 1)) $(($1 & 1))$2
done
echo "$1$2"
}
echo $(for i in 0 1 2 5 50 9000; do bin $i; done)</syntaxhighlight>
{{out}}
<pre>0 1 10 101 110010 10001100101000</pre>
=={{header|VBA}}==
'''2 ways :'''
|