Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Compacting information into a string...
Message
 
To
23/05/1998 20:38:15
Roberto Cota Rivas
Quid Estrategia Esencial de México
Monterrey, Mexico
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00101456
Message ID:
00101518
Views:
15
>Hello:
>
>I need to do the following:
>
>I have an array of three numbers, and I need to create a string where the first two bytes are the first number, and the second and third bytes are the second and third numbers of the array, respectively. This is because the first number is always above 255, and the other two are always below 255, so they need only one byte of storage. Now my problem is that the values are stored as Numeric data type in the array, and how do i go around "pasting" each of the three numbers into a small string:
>
>Example: the numbers are 1000,2 and 4
>I need something like this:
>
>s=####
>Where the first two ## store the 1000, and the second and third # store the last two numbers.
>
>How do I do this in Fox Pro?
>Any help is appreciated...

Some of this depends on how you wish to store the number. Assuming low-byte, high byte order, and only minimizing the number of bytes, the following should do:
* a_array is your array
lnlast = ALEN(a_array, 1)
lcresult = ""
FOR lni = 1 TO lnlast
  lnvalue = a_array[lni]
  IF lnvalue > 255
    lcresult = lcresult + CHR(BITAND(lnvalue, 255))
    lnvalue = BITRSHIFT(lnvalue, 8)
    lcresult = lcresult  + CHR(BITAND(lnvalue, 255))
  ELSE
    lcresult = lcresult + CHR(lnvalue)
  ENDIF
NEXT
RETURN lcresult
One note, BINTOC() returns string in inverse (hi-byte, lo-byte) order and the most significant bit, is set (as opposed to cleared) for positive numbers.

hth,
George

Ubi caritas et amor, deus ibi est
Previous
Reply
Map
View

Click here to load this message in the networking platform