'=== Full description for the Bin$() function is available
'=== in the separate HTML document.
'=====================================================================
'-- some usage examples
PRINT "some simple numbers..." num&
= 5:
PRINT num&;
"= "; Bin$
(num&
)num&
= -4:
PRINT num&;
"= "; Bin$
(num&
)num&
= 32000:
PRINT num&;
"= "; Bin$
(num&
)
PRINT "works also with &B, &H and &O..." PRINT " &B1101 = "; Bin$
(&B1101
) PRINT " &H211 = "; Bin$
(&H211) PRINT " &O377 = "; Bin$
(&O377)
PRINT "and even with floating points (converts integer part only)..." num#
= 123.456:
PRINT num#;
"= "; Bin$
(num#
)num#
= -60000.25:
PRINT num#;
"= "; Bin$
(num#
)num#
= 0.5:
PRINT num#;
"= "; Bin$
(num#
)
'-- done
'--- Full description available in separate HTML document.
'---------------------------------------------------------------------
'--- option _explicit requirements ---
DIM temp~&&
, binStr$
, charPos%
, highPos%
'--- init ---
temp~&& = value&&
binStr$
= STRING$(64, "0"): charPos%
= 64: highPos%
= 64'--- convert ---
IF (temp~&&
AND 1) THEN ASC(binStr$
, charPos%
) = 49: highPos%
= charPos%
charPos% = charPos% - 1: temp~&& = temp~&& \ 2
'--- adjust negative size ---
IF -value&&
< &H0080000000~&&
THEN highPos%
= 33 IF -value&&
< &H0000008000~&&
THEN highPos%
= 49 IF -value&&
< &H0000000080~&&
THEN highPos%
= 57 '--- set result ---
Bin$
= MID$(binStr$
, highPos%
)