tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
23
Task/Binary-digits/AWK/binary-digits.awk
Normal file
23
Task/Binary-digits/AWK/binary-digits.awk
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
BEGIN {
|
||||
print tobinary(5)
|
||||
print tobinary(50)
|
||||
print tobinary(9000)
|
||||
}
|
||||
|
||||
function tobinary(num) {
|
||||
outstr = ""
|
||||
l = num
|
||||
while ( l ) {
|
||||
if ( l%2 == 0 ) {
|
||||
outstr = "0" outstr
|
||||
} else {
|
||||
outstr = "1" outstr
|
||||
}
|
||||
l = int(l/2)
|
||||
}
|
||||
# Make sure we output a zero for a value of zero
|
||||
if ( outstr == "" ) {
|
||||
outstr = "0"
|
||||
}
|
||||
return outstr
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue