BigInt and >>>

Andre via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Dec 18 23:39:28 PST 2014


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é


More information about the Digitalmars-d-learn mailing list