Reputation: 35
In Javascript:
255 << 24 = -16777216
In dart:
255 << 24 = 4278190080
Is there any way by which I get the same answer in Dart similar to JS ?
Upvotes: 0
Views: 139
Reputation: 71763
To get precisely the same result in Dart as in JavaScript (whether on the web or not), do:
var jsValue = (255 << 24).toSigned(32);
JavaScript converts all bitwise operations to 32-bit integers, and to signed integers for all operators except >>>
.
So, do .toSigned(32)
on the result to do precisely what JavaScript
does.
Upvotes: 2