Bitwise operators in @formulas

I want to use bitwise operators using @formulas.

Problem is : I want to decode gps-coordinates for encoding polyline using google maps.

I’ve written a ls function to encode a string, but i want i to convert using @formulas.

here is the script (who works very well) :

Function encodedstring(theVal As String)

Dim parts As Variant

Dim x As String

Dim w As Integer

Dim v As Long



parts = Split(theVal, ".")

x = parts(0)+Left(parts(1)+"00000",5)

v = Val(x) * 2

If v < 0 Then v = (Not v)

While (v >= 32)

	w = (v And 31)

	v = (v -w)/32

	encodedstring =  encodedstring + Chr((w Or 32)+63)

Wend

encodedstring =  encodedstring + Chr((v )+63)

End Function

The polyline algorithm is explaned on : Encoded Polyline Algorithm Format  |  Google Maps Platform  |  Google for Developers

Subject: bitwise operators in @formulas

I think that you can always use “normal” arithmatic to simulate bitwise operations.

Subject: RE: bitwise operators in @formulas

Rob,no. e.i. !(negative value) returns allways zero

(already tested)

Subject: RE: bitwise operators in @formulas

There are no bitwise operators in Formula Language. Yes, you CAN convert the script to formula, but only somebody who was a little bit insane would bother. Let me illustrate…

In order to do “bitwise” operations in Formula Language (which has only “bulk Booleans” – 0 is @False and any other number will convert to @True), you need to make the operations list-wise. The number you put in needs to be converted to a “bit list” by taking the modulo 2 value of the number, appending that to the front of the bit list, dividing the number by 2 and taking the integer until the number is all gone. Then you may need to invert the list if the number is negative, and pad the list out to the required length. Then each of the five-bit subsets needs to be converted to a decimal value (by the double-dabble method). Adding 63 and using @Char is the easy part.

Now keep in mind that you need to duplicate this function for the longitude. And that if you are actually doing a polyline, you need one copy of the code for each of the latitude and longitude values for each of the way points, since there is no such thing as a “function” in Formula Language. Oh, and you’ll need to add a bunch of @Ifs to make it usable for different point counts. The formula will become too long to save in a hurry, although you could presumably split the calculations up among a number of fields.

You have a working script. Why not use it?

Subject: RE: bitwise operators in @formulas

Hi Stan,

rewriting the script using @formulas will result in a lot of @do, @if, @while

Regards

Jan

see first result at : http://www.wandelwereld.be/jvanmeir/jan.nsf/reedsgewandeld.html (Beta version)