Task

Create and display the sequence of binary digits for a given   non-negative integer.

   The decimal value      5   should produce an output of               101
   The decimal value     50   should produce an output of            110010
   The decimal value   9000   should produce an output of    10001100101000

The results can be achieved using built-in radix functions within the language   (if these are available),   or alternatively a user defined function can be used.

The output produced should consist just of the binary digits of each number followed by a   newline.

There should be no other whitespace, radix or sign markers in the produced output, and leading zeros should not appear in the results.




 
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
 