1. Registered User
Join Date
Dec 2013
Posts
3

Ternary operator

Hi

Can someone help me to translate this code:
Code:
```  return  ( ( ayr[7] >> ch   | tons >> ch )
& ( ayr[7] >> ch+3 | noiv       )
& 1 )  * amp[ ayr[8+ch] & 0x10
? envv
: ayr[8+ch] & 0x0f ];```
in to IF ELSE expression?

Thank´s

2. Can you expand on what is supposed to do?

Also, the AND logical comparison is && not a single & character.
And the logical OR is || not | only.
Is your >> supposed to be some sort of right shift operation?

3. Not that it's any easier to read:
Code:
```if (ayr[8+ch] & 0x10)
return (( ( ayr[7] >> ch   | tons >> ch )
& ( ayr[7] >> ch+3 | noiv       )
& 1 )  * amp[envv];
else
return ( ( ayr[7] >> ch   | tons >> ch )
& ( ayr[7] >> ch+3 | noiv       )
& 1 )  * amp[ayr[8+ch] & 0x0f];```
JRMKR, those are all bitwise and's and or's and shifts.

4. Originally Posted by tracknut
Not that it's any easier to read:
Code:
```if (ayr[8+ch] & 0x10)
return (( ( ayr[7] >> ch   | tons >> ch )
& ( ayr[7] >> ch+3 | noiv       )
& 1 )  * amp[envv];
else
return ( ( ayr[7] >> ch   | tons >> ch )
& ( ayr[7] >> ch+3 | noiv       )
& 1 )  * amp[ayr[8+ch] & 0x0f];```
JRMKR, those are all bitwise and's and or's and shifts.
That was my point. It was not syntax correct.
Still does not make it any easier to decipher without some comments.
I would think 2 weeks away from the code will not make it any easier to decipher than a 6 month hiatus.

5. I'm missing the part that's not syntactically correct, but certainly agree it's a nightmare to decipher...

6. Originally Posted by tracknut
I'm missing the part that's not syntactically correct, but certainly agree it's a nightmare to decipher...
I'm referring to the original post.

Note also that '&' alone is supposed to do what in your post?

7. Registered User
Join Date
Dec 2013
Posts
3
Code:
```function cstep(ch) {
if( ++ayr[ch+16] >= (ayr[ch<<1] | ayr[1|ch<<1]<<8) )
ayr[ch+16]= 0,
tons^= 1 << ch;
return  ( ( ayr[7] >> ch   | tons >> ch )
& ( ayr[7] >> ch+3 | noiv       )
& 1 )  * amp[ ayr[8+ch] & 0x10
? envv
: ayr[8+ch] & 0x0f ];
}```
This is the complete function that i'm translating to Purebasic syntax.
The first part is not so hard to undesrtand, but i'm very confusing about the 'return ' part. With IF ELSE statements is more easy to understand.
Mostly are bitwise operations.

8. Originally Posted by JMRKER
I'm referring to the original post.

Note also that '&' alone is supposed to do what in your post?
Whether the OP or the one I provides, here's an English version for this:
Code:
```	return (( ( ayr[7] >> ch   | tons >> ch )
& ( ayr[7] >> ch+3 | noiv       )
& 1 )  * amp[envv];```
"take the value of (( ayr[7] >> ch | tons >> ch) and bitwise and it with (ayr[7] >> ch+3 | noiv ) and bitwise and the result with 1 (i.e. get the value of the low order bit). Multiply the result by amp[envv], and return that value. So the returned value will either be zero or amp[envv], depending on the low order bit of the result of all the shifting, or'ing and and'ing"

...and that's only the first half of it

9. Registered User
Join Date
Dec 2013
Posts
3
@tracknut
Thank you!

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•