
function binarystr(sys ii, optional nd) as string
=================================================
if ii=0 and nd=0 then return "0"
int b,j,n,p
string bi
b=1
n=nd
if n=0 then n=8*sizeof sys
p=n
bi=space n
for j=n to 1 step -1
  if ii and b
    mid bi,j,"1"
    p=j
  else
    mid bi,j,"0" 
  end if
  shl b,1
next
if nd=0
  return mid bi,p 'trim leading zeros
else
  return bi
end if
end function


print binaryStr 42
print binaryStr 42,8
