VFP provides the BITSET() function to set a bit in a numeric value directly.
There's no need to do all those conversions. Just work with numeric values.
Vlad
>>>I need to convert a binary number to Hex, and vice-versa. It's been a long time since I've done this. Does anyone have some code that will do this for me?
>>>
>>>The binary number will look something like: 1100001111010001 (It will be as much as 16 digits)
>>>
>>>Craig
>>
>>Hi Craig,
>>
>>I'd suggest a two step approach, the first being to convert the binary string to an integer, then covert the integer to hex. I recently saw a routine to do the latter conversion, so here's the first part:
>>
>>FUNCTION BStr2Int
>>
>>LPARAMETER pc_bstr
>>
>>LOCAL lnresult, lni, lnj, lnlast
>>lnlast = LEN(pc_bstr)
>>lnj = -1
>>lnresult = 0
>>FOR lni = lnlast TO 1 STEP -1
>> lnj = lnj + 1
>> lnresult = lnresult + (VAL(SUBSTR(pc_bstr, lni, 1)) * (2 ^ lnj))
>>NEXT
>>RETURN lnresult
>>
>>Regards,
>>
>>George
>
>
>Thanks George, I'll try it out. What I'm needing to do is transmit data to a remote server program. The remote program can accept optional fields i the middle of the string. The first field to send is a hex representation of the binary on/off (yes/no) of which fields are sent. For example, if field 5 is sent, then the 5th position in the binary number is set, etc.
>
>Craig
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement