Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Number to binary to number
Message
 
 
À
14/06/2006 03:34:28
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01128906
Message ID:
01129019
Vues:
14
Jos,

A static array lookup is going to do this a lot faster than a character by character conversion:
dimension gaHexToBin[16]

gaHexToBin[1]  = '0000'
gaHexToBin[2]  = '0001'
gaHexToBin[3]  = '0010'
gaHexToBin[4]  = '0011'
gaHexToBin[5]  = '0100'
gaHexToBin[6]  = '0101'
gaHexToBin[7]  = '0110'
gaHexToBin[8]  = '0111'
gaHexToBin[9]  = '1000'
gaHexToBin[10] = '1001'
gaHexToBin[11] = '1010'
gaHexToBin[12] = '1011'
gaHexToBin[13] = '1100'
gaHexToBin[14] = '1101'
gaHexToBin[15] = '1110'
gaHexToBin[16] = '1111'

lnValue = 12345
lcHexValue = substr( transform( lnValue, '@0' ), 3 )
lcBinValue = ''
for i = 1 to 8
   lcBinValue = lcBinValue + gaHexToBin[val( substr( lcHexValue, i, 1 ) ) + 1]
endfor

? lcBinValue
>I have written my own number to binary to number function but I thought I would ask if there was an easier method. I am looking to take number eg 123456 and convert that into a binary string like "00000000000000011110001001000000". Is there a fast way to do this num to char-bin and back to number?
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform