RosettaCodeData/Task/Binary-digits/M2000-Interpreter/binary-digits.m2000

54 lines
1.9 KiB
Plaintext

Module Checkit {
Form 90, 40
Function BinFunc${
Dim Base 0, One$(16)
One$( 0 ) = "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"
=lambda$ One$() (x, oct as long=4, bypass as boolean=True) ->{
if oct>0 and oct<5 then {
oct=2*(int(4-oct) mod 4+1)-1
} Else oct=1
hx$ = Hex$(x, 4 )
Def Ret$
If Bypass then {
For i= oct to len(hx$)
if bypass Then if Mid$(hx$, i, 1 )="0" Else bypass=false
If bypass and i<>Len(hx$) Then Continue
Ret$ += One$( EVal( "0x" + Mid$(hx$, i, 1 ) ) )
Next i
oct=instr(Ret$, "1")
if oct=0 then {
Ret$="0"
} Else Ret$=mid$(Ret$, oct)
} Else {
For i= oct to len(hx$)
Ret$ += One$( EVal( "0x" + Mid$(hx$, i, 1 ) ) )
Next i
}
=Ret$
}
}
Bin$=BinFunc$()
Stack New {
Data 9, 50, 9000
While not empty {
Read x
Print Format$("The decimal value {0::-10} should produce an output of {1:-32}",x, Bin$(x) )
}
}
Stack New {
Data 9, 50, 9000
While not empty {
Read x
Print Format$("The decimal value {0::-10} should produce an output of {1:-32}",x, Bin$(x,,false) )
}
}
Stack New {
Data 9, 50, 9000
While not empty {
Read x
Print Bin$(x)
}
}
}
Checkit