/    Sign up×
Community /Pin to ProfileBookmark

Did anyone see this operator? |=

I’ve seen recently the following operator in use:

variable [COLOR=Red]|=[/COLOR] 0;

How does it work? It’s hard to search google for small strings like that, so I ask here…

Thanks

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Jeff_MottJun 14.2005 — The single pipe is the bitwise OR operator, combined with the shorthand assignment notation. So that expression is equivalent to

[font=courier new]variable = variable | 0;[/font]

For more information see

http://www.croczilla.com/~alex/reference/javascript_ref/

http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
Copy linkTweet thisAlerts:
@maciej64authorJun 15.2005 — Thank you very much for your help!
Copy linkTweet thisAlerts:
@UltimaterJun 15.2005 — I remember when I encounter the operator myself and it took me a while to understand it.
<i>
</i>&lt;script type="text/javascript"&gt;
var temp1=544
temp1|=213
alert(temp1)//757
//Why the computer spits-out 757:
//1[color=royalblue]0[/color]0010[color=royalblue]0[/color]0[color=royalblue]0[/color]0 which is 544
//0[color=royalblue]0[/color]1101[color=royalblue]0[/color]1[color=royalblue]0[/color]1 which is 213
//-----------------------
//1[color=royalblue]0[/color]1111[color=royalblue]0[/color]1[color=royalblue]0[/color]1 which is 757

&lt;/script&gt;
Copy linkTweet thisAlerts:
@UltimaterJun 15.2005 — Might as well teach you the bitwise AND operator now
<i>
</i>&lt;script type="text/javascript"&gt;
var temp1=818
temp1&amp;=503
alert(temp1)//306
//Why the computer spits-out 306:
//1[color=royalblue]1[/color]00[color=royalblue]1[/color][color=royalblue]1[/color]00[color=royalblue]1[/color]0 which is 818
//0[color=royalblue]1[/color]11[color=royalblue]1[/color][color=royalblue]1[/color]01[color=royalblue]1[/color]1 which is 503
//-----------------------
//0[color=royalblue]1[/color]00[color=royalblue]1[/color][color=royalblue]1[/color]00[color=royalblue]1[/color]0 which is 306

&lt;/script&gt;
×

Success!

Help @maciej64 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...