I have this nice code, that can only be run once due to a global variable:
Code:
? unbitwise(15)
? unbitwise(35)
Function unbitwise($x)
Dim $factor,$bit
$factor=1
While ($x>=$Factor)
$bit=$factor
$Factor=$Factor*2
Loop
If $tmp
$tmp=$tmp+","+$bit
Else
$tmp="$bit"
EndIf
$x=$x-$bit
If $x
$nul=unbitwise($x)
EndIf
$unbitwise=$tmp
EndFunction
So, it needs to be fixed... Here's my current thought pattern; some sort of recursion with an optional pointer that get passed up the river. Problem is, it gets lost coming back down the river. You'll probably have better luck starting from the original above as I went off in few directions below. My head hurts.
Code:
? unbitwise(15)
? unbitwise(35)
Function unbitwise($x,optional $tmp)
Dim $factor,$bit,$tmp,$tmp2,$flag
$factor=1
While ($x>=$Factor)
$bit=$factor
$Factor=$Factor*2
Loop
If $tmp
? "has "$tmp
$tmp=$tmp+","+$bit
;$unbitwise=$tmp
Else
? "has not"
$tmp="$bit"
;$unbitwise=$tmp
EndIf
$x=$x-$bit
If $x
$tmp2=unbitwise($x,$tmp)
Else
If Not $Flag
$tmp2=$tmp
$Flag=1
EndIf
? "Check1 "$tmp2
EndIf
? "Check2 "$tmp2
EndFunction