zigzag-encoding

Bitwise operations, wrong result in Dart2Js

淺唱寂寞╮ 提交于 2021-02-19 04:51:56
问题 I'm doing ZigZag encoding on 32bit integers with Dart. This is the source code that I'm using: int _encodeZigZag(int instance) => (instance << 1) ^ (instance >> 31); int _decodeZigZag(int instance) => (instance >> 1) ^ (-(instance & 1)); The code works as expected in the DartVM. But in dart2js the _decodeZigZag function is returning invalid results if I input negativ numbers. For example -10 . -10 is encoded to 19 and should be decoded back to -10 , but it is decoded to 4294967286 . If I run

Bitwise operations, wrong result in Dart2Js

折月煮酒 提交于 2021-02-19 04:51:52
问题 I'm doing ZigZag encoding on 32bit integers with Dart. This is the source code that I'm using: int _encodeZigZag(int instance) => (instance << 1) ^ (instance >> 31); int _decodeZigZag(int instance) => (instance >> 1) ^ (-(instance & 1)); The code works as expected in the DartVM. But in dart2js the _decodeZigZag function is returning invalid results if I input negativ numbers. For example -10 . -10 is encoded to 19 and should be decoded back to -10 , but it is decoded to 4294967286 . If I run