| |
| Posted by Andre | PermalinkReply |
|
Andre
| 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 that
>>> is not supported for "BigInt"?
void 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é
|