Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Number to binary to number
Message
From
15/06/2006 01:50:13
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01128906
Message ID:
01129195
Views:
12
Hi David and All. Thanks all for the suggestions. My functions are more or less the same approach as the suggestions made so I'll stick with them.

Many thanks.


>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?
In the End, we will remember not the words of our enemies, but the silence of our friends - Martin Luther King, Jr.
Previous
Reply
Map
View

Click here to load this message in the networking platform