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.
Related
This question already has an answer here:
ECMAScript 6 negative binary literal
(1 answer)
Closed 3 years ago.
So 0b1 is 1. How to write -1 in binary format?
The docs says that the leftmost bit is reserved for sign, but where is that leftmost bit? Even 0b11111111111111111111111111111111 is still a positive number. I naively tried 1b with no success of course.
try
let a = -0b1;
console.log(a);
This question already has an answer here:
How to use xor functionality in angular js expression? [closed]
(1 answer)
Closed 6 years ago.
<form name="businessFormAbout" ng-show="(businessFormAbout.$submitted)^(businessForm.$submitted)">
This line shows error in console:
[$parse:lexerr] Lexer Error: Unexpected next character at columns 30-30 [^] in expression [(businessFormAbout.$submitted)^(businessForm.$submitted)]
It's not AngularJS that doesn't support XOR: JavaScript itself doesn't support XOR as you might define it.
JS does have a bitwise XOR operator (^), but this only works for numbers.
You could create your own XOR function a bit like this:
function XOR(a,b) {
return ( a || b ) && !( a && b );
}
This question already has answers here:
What do these JavaScript bitwise operators do?
(3 answers)
Closed 9 years ago.
I am trying to figure out this operator on JS -
'string' ^= 'string';
But I can not find ant information.
Is that a comparison or assignment ?
Thanks.
myVar ^= 5 is the same as myVar = myVar ^ 5. ^ is the bitwise xor operator
Let's say myVar was set to 2
5 in binary is: 101
2 in binary is: 010
Exclusive "or" checks the first bit of both numbers and sees 1,0 and returns 1 then sees 0,1 and returns 1 and sees 1,0 and returns 1.
Thus 111 which converted back to decimal is 7
So 5^2 is 7
var myVar = 2;
myVar ^= 5;
alert(myVar); // 7
^ (caret) is the Bitwise XOR (Exclusive Or) operator. As with more common operator combinations like +=, a ^= b is equivalent to a = a^b.
See the Javascript documentation from Mozilla for more details.
x ^= y is bitwise XOR and shorthand for x = x^y - and so is technically an "assignment" to answer your question. And to be precise the single operator '^' indicates the bitwise XOR.
As d'alar'cop (and several others by now) already pointed out, this means something called XOR. I always hate to read a wikipedia explanation, so I'm going to put another explanation here:
'XOR' means 'eXclusive OR'. What is that? First an example:
11000110 -- random byte
10010100
--------- ^ -- XOR
01010010
XOR is some bitwise operation, returning two if one of two bits is 1 and the other 0. If they're both 1, it's 'and', not 'exclusive or' ('normal or' would allow two 1's).
This question already has answers here:
What does the ^ (caret) symbol do in JavaScript?
(5 answers)
Closed 6 years ago.
I thought that Math.pow(2,2) was equal to 2^2 but it is not. So what does ^ (caret) mean in JavaScript?
I was executing some tests in the console but didn't recognize the results:
2 ^ 2 = 0
2 ^ 3 = 1
1 ^ 2 = 3
It means bitwise XOR.
EDIT: Fixed link
It's a bitwise integer XOR operation (MDC link).
The ^ operator is bitwise XOR, you have more information in MDN:
https://developer.mozilla.org/en/JavaScript/Reference/Operators/Bitwise_Operators
That operator performs the logical XOR operation. (out bit is 1 when both input bits are different).
This is the bitwise XOR operator, which returns a one for each position where one (not both) of the corresponding bits of its operands is a one. The next example returns 4 (0100):
Code:
result = a ^ b;
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