# Binary "Shift Left" operator? Classic List Threaded 8 messages Open this post in threaded view
|

## Binary "Shift Left" operator?

 I am reverse engineering a Javascript function which uses a "shift left" operator: > Shift Left Operator > > The shift left operator is binary. The syntax is > > *operand1* << *operand2* > >  You obtain the result of the expression by treating *operand1* as a set > of 32 bits and shifting the bits left by the value in *operand2*. > High-order bits are discarded, and the low-order bits are filled with 0's. > > Example: > > var tmp = 31 << 3; > >  In this example, *operand1* is 31 (00000000000000000000000000011111) and > *operand2* is 3. tmp is set to 248 (00000000000000000000000011111000). > Is there an equivalent in Rev - if not can anyone translate this to some basic math functions? _______________________________________________ use-revolution mailing list [hidden email] Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Open this post in threaded view
|

## Re: Binary "Shift Left" operator?

 At 5:23 PM +0100 4/29/08, David Bovill wrote: >Is there an equivalent in Rev - if not can anyone translate this to some >basic math functions? Shift left is the same as * 2. 31 << 3 would be the same as * 8. What was it that you needed to achieve? _______________________________________________ use-revolution mailing list [hidden email] Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Open this post in threaded view
|

## Re: Binary "Shift Left" operator?

 In reply to this post by david bovill 2008/4/29 Colin Holgate <[hidden email]>: > At 5:23 PM +0100 4/29/08, David Bovill wrote: > > > Is there an equivalent in Rev - if not can anyone translate this to some > > basic math functions? > > > > Shift left is the same as * 2. 31 << 3 would be the same as * 8. > > What was it that you needed to achieve? > I'm making a start on the Map library as part of a suite of open source API libraries. This JavaScript function is for a Mercator Projection used in Google maps amongst others. The script looks like this: function Adjust(x,y,deltaX,deltaY,z) > { > var offset=268435456; > var radius=offset/Math.PI; > > function LToX(x) > { > return Math.round(offset+radius*x*Math.PI/180); > } > > function LToY(y) > { > return Math.round(offset-radius*Math.log((1+Math.sin(y*Math.PI/180))/(1-Math.sin(y*Math.PI/180)))/2); > } > > function XToL(x) > { > return ((Math.round(x)-offset)/radius)*180/Math.PI; > } > > function YToL(y) > { > return (Math.PI/2-2*Math.atan(Math.exp((Math.round(y)-offset)/radius)))*180/Math.PI; > } > > return {x:XToL(LToX(x)+(deltaX<<(21-z))),y:YToL(LToY(y)+(deltaY<<(21-z)))}; > } > > And its the last line that looks tricky. The > deltaX<<(21-z) > > is the bit I guess i am looking most to figure out? _______________________________________________ use-revolution mailing list [hidden email] Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Open this post in threaded view
|

## Re: Binary "Shift Left" operator?

 Not sure how many bits of arithmetic are being assumed there, but shift would also have a modulus effect. If I'm right, and if it's 32 bit, n << 21 might be like n mod 512 * 2^21. I just made this: http://staff.funnygarbage.com/colin/mapcalc.swfIt will let you play with values while you try to work out the relationships! _______________________________________________ use-revolution mailing list [hidden email] Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Open this post in threaded view
|

## Re: Binary "Shift Left" operator?

 In reply to this post by david bovill David- >> deltaX<<(21-z) >> >> is the bit I guess i am looking most to figure out? Howz about repeat (21-z) times  put deltaX * 2 into deltaX end repeat --  Mark Wieder  [hidden email] _______________________________________________ use-revolution mailing list [hidden email] Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution --  Mark Wieder  ahsoftware@gmail.com
Open this post in threaded view
|