digitalmars.D.learn - BigInt and >>>
- Andre (31/32) Dec 18 2014 Hi,
- bearophile (7/8) Dec 19 2014 Try:
- Andre (4/12) Dec 19 2014 Great! Thanks a lot.
Hi, I try to translate following javascript coding to D: i = buffer[2] << 16; i |= buffer[1] << 8; i |= buffer[0]; i += buffer[3] << 24 >>> 0; Buffer is: [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 111] Expected result for i is: 4294967295 But in D the last statement returns -1, the previous 3 statements returns the same values like in JavaScript. I tried "long" and also like in the example "BigInt", both do not work correctly. In the documentation it is also mentioned thatvoid main() { import std.stdio; import std.bigInt; auto buffer = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 111]; BigInt i; i = buffer[2] << 16; i |= buffer[1] << 8; i |= buffer[0]; i += buffer[3] << 24 >>> 0; writeln("i: ", i); } Do you have any idea how to translate the coding correctly? Kind regards Andréis not supported for "BigInt"?
Dec 18 2014
Andre:Do you have any idea how to translate the coding correctly?Try: i += long(buffer[3]) << 24 >>> 0; But I also suggest to add parentheses, to make the code less unreadable for humans. Bye, bearophile
Dec 19 2014
Great! Thanks a lot. Kind regards André On Friday, 19 December 2014 at 08:47:50 UTC, bearophile wrote:Andre:Do you have any idea how to translate the coding correctly?Try: i += long(buffer[3]) << 24 >>> 0; But I also suggest to add parentheses, to make the code less unreadable for humans. Bye, bearophile
Dec 19 2014