Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
37
Task/Bitwise-IO/Lingo/bitwise-io-2.lingo
Normal file
37
Task/Bitwise-IO/Lingo/bitwise-io-2.lingo
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
----------------------------------------
|
||||
-- @param {string} str - ASCII string
|
||||
-- @return {instance} BitArray
|
||||
----------------------------------------
|
||||
on crunchASCII (str)
|
||||
ba = script("BitArray").new(str.length * 7)
|
||||
pow2 = [64,32,16,8,4,2,1]
|
||||
pos = 1
|
||||
repeat with i = 1 to str.length
|
||||
n = chartonum(str.char[i])
|
||||
repeat with j = 1 to 7
|
||||
ba.setBit(pos, bitAnd(n, pow2[j])<>0)
|
||||
pos = pos+1
|
||||
end repeat
|
||||
end repeat
|
||||
return ba
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
-- @param {instance} bitArray
|
||||
-- @return {string} ASCII string
|
||||
----------------------------------------
|
||||
on decrunchASCII (bitArray)
|
||||
str = ""
|
||||
pow2 = [64,32,16,8,4,2,1]
|
||||
pos = 1
|
||||
cnt = bitArray.bitSize/7
|
||||
repeat with i = 1 to cnt
|
||||
n = 0
|
||||
repeat with j = 1 to 7
|
||||
n = n + bitArray.getBit(pos)*pow2[j]
|
||||
pos = pos+1
|
||||
end repeat
|
||||
put numtochar(n) after str
|
||||
end repeat
|
||||
return str
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue