What does JavaScript >> stand for? [duplicate] - javascript

This question already has answers here:
What do these JavaScript bitwise operators do?
(3 answers)
Closed 8 years ago.
I'm translating a JavaScript algorithm into PHP, and I ran into the symbol >>, and I have no clue what it means. It's hard to search Google for symbols, so can anyone tell me what it means?

It's a bit shifting operator:
http://www.contactor.se/~dast/fpl-old/language/shift.HTML

It is a sign-propagating right shift. Many, many, languages have this operator.
Wikipedia has a good article on the subject. My first link has a few examples and an explanation.

Other answers are correct, but this may be of help to you: If x is positive then
x >> y
is the same as
floor(x / (2 ** y))
where 2**y is 2 raised to the power y.
E.g. x >> 3 is the same as floor(x / 8).

Bitwise right shift
Looks like PHP has this operator too:
http://us2.php.net/operators.bitwise

Related

How to use operator "^" in JavaScript? [duplicate]

This question already has an answer here:
How to have a number to be a power?
(1 answer)
Closed 3 years ago.
I'm trying to use ^ operator in javascript, like:
0.66666666666666666666666666666667^1.5
should equal
0,54433105395181735515495201660131
But when I'm trying to do it, it won't return me anything, it will return either 67,0 or 1, depending on my attempts.
Desired Output
console.log(100 * 0.66666666666666666666666666666667^1.5);
How do I solve this problem?
You need to take the exponenciation operator **instead of bitwise XOR ^.
Alternate use the classing Math.pow.
console.log(0.66666666666666666666666666666667 ** 1.5)
^ means XOR in JavaScript. If you want exponentiation, you have to use Math.pow or ** instead.

What does `>>>` mean in JavaScript? [duplicate]

This question already has answers here:
What is the JavaScript >>> operator and how do you use it?
(7 answers)
Closed 5 years ago.
What is the meaning of the expression >>> in JavaScript? It is like type conversion, or what, and when it recommended to use?
I ran into that symbol (>>>) when I read this article and am a little confused.
Sorry, if my question is stupid, but I can not find any answers by Google search or other ways.
>>> is a bitwise operator.
>>> (Zero-fill right shift) This operator shifts the first operand the specified number of bits to the right. Excess bits shifted off to the
right are discarded. Zero bits are shifted in from the left. The sign
bit becomes 0, so the result is always non-negative.
For non-negative numbers, zero-fill right shift and sign-propagating
right shift yield the same result. For example, 9 >>> 2 yields 2, the
same as 9 >> 2
From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators

What is this JavaScript operator doing? [duplicate]

This question already has answers here:
What do these JavaScript bitwise operators do?
(3 answers)
Closed 8 years ago.
I've seen the following:
((2 * 45) + (2 * 124) + 100) >>> 3
Putting this in a console on its own reveals the value 54.
What is the purpose of >>> 3?
This is the Zero-fill right shift bitwise operator.
From the Mozilla Developer Network docs:
This operator shifts the first operand the specified number of bits to the right. Excess bits shifted off to the right are discarded. Zero bits are shifted in from the left. The sign bit becomes 0, so the result is always non-negative.

What is "~" represent in this JavaScript? [duplicate]

This question already has answers here:
What does a tilde do when it precedes an expression?
(5 answers)
Closed 8 years ago.
I am not a JavaScript expert, but I'm reading the code and found out that there's a statement like this.
if(!~dssClass.indexOf("hideDiv")
What's the "~" mean in this statement?
Thanks
It's bitwise NOT: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
"take the result of the indexOf lookup, bitwise invert it, then take the logical NOT of that"

What is this JavaScript operator mean? >>> [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What is the JavaScript >>> operator and how do you use it?
I was browsing through some documentation on MDN for the indexOf workaround (link) and I came across this line of code:
var len = t.length >>> 0;
Was just curious what that did, as I've never seen it.
Answer is in the first comment.
Unsigned right shift. See Unsigned Right Shift Operator (>>>) (JavaScript)
.

Categories