/    Sign up×
Community /Pin to ProfileBookmark

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 ];
[/CODE]

in to IF ELSE expression?

Thank´s

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERDec 23.2013 — 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?

?
Copy linkTweet thisAlerts:
@tracknutDec 23.2013 — Not that it's any easier to read:
<i>
</i>if (ayr[8+ch] &amp; 0x10)
return (( ( ayr[7] &gt;&gt; ch | tons &gt;&gt; ch )
&amp; ( ayr[7] &gt;&gt; ch+3 | noiv )
&amp; 1 ) * amp[envv];
else
return ( ( ayr[7] &gt;&gt; ch | tons &gt;&gt; ch )
&amp; ( ayr[7] &gt;&gt; ch+3 | noiv )
&amp; 1 ) * amp[ayr[8+ch] &amp; 0x0f];


JRMKR, those are all bitwise and's and or's and shifts.
Copy linkTweet thisAlerts:
@JMRKERDec 23.2013 — Not that it's any easier to read:
<i>
</i>if (ayr[8+ch] &amp; 0x10)
return (( ( ayr[7] &gt;&gt; ch | tons &gt;&gt; ch )
&amp; ( ayr[7] &gt;&gt; ch+3 | noiv )
&amp; 1 ) * amp[envv];
else
return ( ( ayr[7] &gt;&gt; ch | tons &gt;&gt; ch )
&amp; ( ayr[7] &gt;&gt; ch+3 | noiv )
&amp; 1 ) * amp[ayr[8+ch] &amp; 0x0f];


JRMKR, those are all bitwise and's and or's and shifts.[/QUOTE]


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.
Copy linkTweet thisAlerts:
@tracknutDec 23.2013 — I'm missing the part that's not syntactically correct, but certainly agree it's a nightmare to decipher... ?
Copy linkTweet thisAlerts:
@JMRKERDec 24.2013 — I'm missing the part that's not syntactically correct, but certainly agree it's a nightmare to decipher... ?[/QUOTE]

I'm referring to the original post.

Note also that '&' alone is supposed to do what in your post?
Copy linkTweet thisAlerts:
@JRobertoauthorDec 24.2013 — [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 ];
}
[/CODE]


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.
Copy linkTweet thisAlerts:
@tracknutDec 24.2013 — I'm referring to the original post.

Note also that '&' alone is supposed to do what in your post?[/QUOTE]


Whether the OP or the one I provides, here's an English version for this:
<i>
</i> return (( ( ayr[7] &gt;&gt; ch | tons &gt;&gt; ch )
&amp; ( ayr[7] &gt;&gt; ch+3 | noiv )
&amp; 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 ?
Copy linkTweet thisAlerts:
@JRobertoauthorDec 24.2013 — @tracknut

I will try your code.

Thank you!
×

Success!

Help @JRoberto spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,
)...