Hi guys! Since it's getting close to the next challenge. I thought I'd post up my solution for last month's challenge.

table = [1, 2, 4, 8, 16, 32, 64, 128]
rtable = [128, 64, 32, 16, 8, 4, 2, 1]
//TASK #1
task1_n = random(255)
function _abs(x)
r = 0
if x < 0 then r = (~x) + 1
else r = x endif
return r
function extract_bin(n)
r = "00000000"
for i = 0 to 8 loop
if n & rtable[i] then r[i] = "1"
else r[i] = "0" endif
repeat
return r
function reverse_bin(n)
r = 0
for i = 0 to 8 loop
if n & table[i] then
r = r | rtable[i]
endif
repeat
return r
print(str(task1_n) + " " + extract_bin(task1_n) + " -> " + str(reverse_bin(task1_n)) + " " + extract_bin(reverse_bin(task1_n)))
//TASK #2
task2_n1 = random(255)
task2_n2 = random(255)
is_negative1 = random(2)
is_negative2 = random(2)
function mul(a, b)
r = 0
sign = 0
loops = 0
if a == 0 or b == 0 then r = 0 else
if a == 1 then r = b else
if a == -1 then r = -b else
if b == 1 then r = a else
if b == -1 then r = -a else
if a < 0 or b < 0 then sign = 1 endif
if a < 0 and b < 0 then sign = 0 endif
a = _abs(a)
b = _abs(b)
for i = 0 to 8 loop
if b & table[i] then
r += a
endif
a = a << 1
loops += 1
repeat
endif endif endif endif endif
if sign then r = -r endif
res = [r, loops]
return res
if is_negative1 then task2_n1 = -task2_n1 endif
if is_negative2 then task2_n2 = -task2_n2 endif
task2_res = mul(task2_n1, task2_n2)
print(str(task2_n1) + " x " + str(task2_n2) + " = " + str(task2_res[0]) + " in " + str(task2_res[1]))