二进制的数字怎么获取?
我想用二进制表示数字,该用什么命令?比如:十进制0,二进制是0
十进制1,二进制是1
十进制2,二进制是10
十进制3,二进制是11
十进制4,二进制是100
十进制5,二进制是101
....
请问有这样的命令吗?
FOR i=0 TO 255 ? NumToBin(i) ENDFOR FUNCTION NumToBin(num) LOCAL i,num,bin num = BITAND(num,0xFFFFFFFF) bin = "" FOR i=31 TO 0 STEP -1 bin = bin + TRANSFORM(BITAND(BITRSHIFT(num,i),1)) ENDFOR RETURN bin ENDFUNC
PARAMETERS num LOCAL nanswer,nremainder,creturn creturn="" DO WHILE .t. nanswer=INT(num/2) nremainder=MOD(num,2) IF nanswer>1 num=nanswer creturn=TRANSFORM(nremainder)+creturn loop ELSE IF nanswer<1 creturn=TRANSFORM(nremainder)+creturn ELSE creturn=TRANSFORM(nanswer)+TRANSFORM(nremainder)+creturn ENDIF exit ENDIF ENDDO creturn=PADL(creturn,32,"0") RETURN creturn