Welcome to the Parallax Discussion Forums, sign-up to participate.

# Trying to understand operators.

Posts: 7
Hi again Smart People,

SPIN is kicking my butt a bit. My past experience is ZX Spectrum BASIC. In simple English would someone please decipher this so I may wrap my head around how I would have done it in BASIC?

x_value = x1+(x1->2)+(x1->4)

Any help would be appreciated.

Thank you.

• Posts: 22,897
The "->" operation is a 32-bit rotate right. There's no equivalent in Basic. "x1->2" takes the low order 2 bits of x1 and rotates them into bit positions 31 and 30 shifting the rest of x1 to the right effectively dividing it by 4. In other words, aaaa bbbb cccc dddd eeee ffff gggg hhhh becomes hhaa aabb bbcc ccdd ddee eeff ffgg gghh. Similarly, "x1->4" takes the low order 4 bits of x1 and rotates them into bit positions 31-28 shifting the rest of x1 to the right effectively dividing it by 16. The rest of the statement just adds the 3 terms together.
• Posts: 1,101
Isn't a divide a shift right, not a rotate right? I cannot think of why you would want to add rotated values.

John Abshier
• Posts: 22,897
Yes, divide by a power of 2 is effectively a shift right. The "->" rotate right isn't quite the same thing. A "~>" using a tilde as the first character is an arithmetic shift right which does act like a divide by a power of 2. Maybe that's what you're actually using.
• Posts: 7
Holy cow! Buckle up because this is going to sound stupid. It is a Tilde. In the Propeller tool on my new 14" monitor the tilde looks like a minus. Now I understand.

KB
• Posts: 6,212
edited 2019-02-05 - 15:43:34
~> is the Spin equivalent of SAR (signed arithmetic shift right); it's useful for dividing signed numbers by powers of 2.
Jon McPhalen
Hollywood, CA
It's Jon or JonnyMac -- please do not call me Jonny.
• Posts: 1,397
CalvinBreen,

It looks like a tilde (~) which I've seen mostly used to sets I/O pins to High and Low values.

All of the Spin operators are listed on Page 144 of the Propeller Manual.

You can see from the table that there are 3 tilde operators which are explained in detail on Pages 156 to 159.
```~ ' Sign-extend from bit 7 (~X) or post-clear to 0 (X~); all bits low, 156
~~ ' Sign-extend from bit 15 (~~X) or post-set to -1 (X~~); all bits high, 157
~> ' Bitwise: Shift arithmetic right, 158
```

• Posts: 7
Excellent, got it. Thank you. Man I love this forum.
• Posts: 2,559
Excellent, got it. Thank you. Man I love this forum.

yeah, be careful, it is addictive...

Enjoy!

Mike
I am just another Code Monkey.
A determined coder can write COBOL programs in any language. -- Author unknown.
Press any key to continue, any other key to quit

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119.
• Posts: 8,242
msrobots wrote: »
Excellent, got it. Thank you. Man I love this forum.

yeah, be careful, it is addictive...

Enjoy!

Mike

So true, but it's a healthy addiction.
In science there is no authority. There is only experiment.
Life is unpredictable. Eat dessert first.