Question

To generate UInt64 the following results in "warning C4293: '<<' : shift count negative or too big, undefined behavior"

UInt64 byteArrayToUInt64(int %stI, array<Byte>^ byteArray) {
    UInt64 retV = byteArrayToUInt32(stI, byteArray);
    retV |= byteArrayToUInt32(stI, byteArray) << 32;
    return retV;
}

or

UInt64 byteArrayToUInt64(int %stI, array<Byte>^ byteArray) {
    stI += 8;
    return byteArray[stI - 8] | byteArray[stI - 7]  << 0x08 |  byteArray[stI - 6]
     << 0x10 |  byteArray[stI - 5]  << 0x18 |  byteArray[stI - 4] << 0x20 |  byteArray[stI - 3]
     << 0x28 |  byteArray[stI - 2]  << 0x30 |  byteArray[stI - 1] << 0x38;
}

Unfortunately, all MS have to say about their UInt64 structure is:

The UInt64 value type represents unsigned integers with values ranging from 0 to 18,446,744,073,709,551,615.

UInt64 provides methods to compare instances of this type, convert the value of an instance to its string representation, and convert the string representation of a number to an instance of this type.

Pretty useless isn't it?

Was it helpful?

Solution

Before shifting the value, you need to static_cast it to an UInt64. Otherwise you are shifting a 32 bit value by 32 positions, and that's undefined behavior. Shifting a 64bit value by 32 positions is ok.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top