Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Bitwise Functions in Clipper '87
Message
 
À
17/12/2000 09:23:44
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00454280
Message ID:
00454558
Vues:
28
Geez, yours is much simpler than the one I eventually came up with...

Here's what I had:

PARAMETER num && number to convert to bits

i = 2 && i is the power to which we're multiplying (bitwise rules)
lcstring = '' && to store the 1's and 0's
lnbits = 8 && loop is dynamic, lnbits is for padding empty spaces

DO WHILE .T.
IF num <= 0 && if <0 we can exit
IF EMPTY(lcstring) && if it started at 0, store 0 to lcstring lcstring = '0'
ENDIF
EXIT
ENDIF

lntemp = INT(num % i) && to get the modulo for the current power

IF lntemp > 0 && if >0 need to place a 1 in the string
lntemp = 1
num = INT(num - (i/2)) && adjust num for next power
ENDIF

i = i * 2 && increment power holder
lcstring = ALLTRIM(STR(lntemp))+lcstring && add 1/0 to lcstring

ENDDO

lcstring = PADL(lcstring,lnbits,'0') && take care of smaller nums

RETURN lcstring
Chris Zangarine
Software Development Engineer
Pipeline Compliance System (PCS)
American Innovations
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform