0

The following expression results different result in Javascript in Python and Javascript:-

Python:-

a, b, c, e, f, h = 271733878, 4023233417, 5858469028, -389564586, 2562383102, 1634886000

a = a + (c & b | ~c & f) + h + e  # 4965557782

Javascript:-

a = 271733878;
b = 4023233417;
c = 5858469028;
e = -389564586
f = 2562383102;
h = 1634886000;

a = a + (c & b | ~c & f) + h + e; // 670590486

console.log(a)

How is the evaluation of the same expression differ in 2 languages?

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Praful Bagai
  • 16,684
  • 50
  • 136
  • 267

1 Answers1

2

~c is evaluated differently in Python and Javascript.

~c is the negation of the c value. This is done by inverting the bits of the value. As such, the value differs in different languages because they probably use a different amount of bits to store int values, which will result in a different ~value.

Javascript:

~c = -1563501733

Python:

~c = -5858469029
H. Figueiredo
  • 888
  • 9
  • 18