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.




 
 
function BinaryBits(sys n) as string
  string buf=nuls 32
  sys p=strptr buf
  sys le
  mov eax,n
  mov edi,p
  mov ecx,32
  '
  'STRIP LEADING ZEROS
  (
   dec ecx
   jl fwd done
   shl eax,1
   jnc repeat
  )
  'PLACE DIGITS
  '
  mov byte [edi],49 '1'
  inc edi
  (
   cmp ecx,0
   jle exit
   mov dl,48 '0'
   shl eax,1
   (
    jnc exit
    mov dl,49 '1'
   )
   mov [edi],dl
   inc edi
   dec ecx
   repeat
  )
  done:
  '
  sub edi,p
  mov le,edi
  if le then return left buf,le
  return "0"
end function
 
print BinaryBits 0xaa 'result 10101010
 