javascript bitwise and confusion [duplicate] - javascript

This question already has answers here:
bitwise AND in Javascript with a 64 bit integer
(6 answers)
Javascript Decimal to Binary - 64 bit
(2 answers)
Closed 1 year ago.
Code like this:
let a = 3232237057
let b = 4294967040
let c = a & b
console.log(a.toString(2))
console.log(b.toString(2))
console.log(c.toString(2))
Output is:
11000000101010000000011000000001
11111111111111111111111100000000
-111111010101111111101000000000
I have expected output like:
11000000101010000000011000000001
11111111111111111111111100000000
11000000101010000000011000000000
What is wrong?

Related

Difference between Bitwise Right Shift and Bitwise Right Shift with Zero in JavaScript? [duplicate]

This question already has answers here:
What is the JavaScript >>> operator and how do you use it?
(7 answers)
What do these JavaScript bitwise operators do?
(3 answers)
Closed 12 days ago.
Can anyone Explain me if i doing -
(10>>>2) = 2
(10>>2) = 2
both same then what difference

Javascript : Addition of 2 numbers always give = 1 [duplicate]

This question already has answers here:
Why does floating-point arithmetic not give exact results when adding decimal fractions?
(31 answers)
How to deal with floating point number precision in JavaScript?
(47 answers)
Closed 3 years ago.
I'm trying to make an addition of the 2 following numbers:
v1 = 0.005919725632510221
v2 = 0.9940802743674898
v1+v2
Result always = 1
Why ?

How does number at JavaScript works [duplicate]

This question already has answers here:
Is floating point math broken?
(31 answers)
How to deal with floating point number precision in JavaScript?
(47 answers)
Closed 3 years ago.
I have this code in javascript
let a = 1;
let b = 0.8;
let c = a-b
I expect the value of c to be equal to 0.2, but the value I get is 0.19999999999999996
does any one have an explanation

Why is the output of this subtraction wrong? [duplicate]

This question already has answers here:
Is floating point math broken?
(31 answers)
How to deal with floating point number precision in JavaScript?
(47 answers)
Closed 4 years ago.
Why is the output of this subtraction wrong?
var a = 1753.10
var b = 87.66
var c = a - b
console.log(c);
The given output is 1665.4399... but the calculator given output is 1665.44

String to Integer in Javascript [duplicate]

This question already has answers here:
javascript large integer round because precision? (why?)
(2 answers)
Javascript long integer
(3 answers)
Closed 4 years ago.
this is code
const str = '1111';
console.log(Number(str));
But When String's length over 17, it will be have problem
const str = '111100000123121221234'
console.log(Number(str)); // 111100000123121220000
I want to know, what's the principle of convert string to Integer of Number Object. Why convert wrong
Thank You Very Much
Because "Integers (numbers without a period or exponent notation) are accurate up to 15 digits". See: https://www.w3schools.com/js/js_numbers.asp

Categories