3 Replies Latest reply on Jun 11, 2015 7:29 AM by JoMe_264151

# Fascinating 64-Bit OR Failure

I've run into a frustrating basic math problem in creator 3.0. I have a function that takes an array of 8-byte values in little-endian format and converts it to a uint64. Very straight forward, except the generated code doesn't actually work. I have tried this multiple ways (from the obvious solution to super long-hand). I verified that the array pointer is passed in, I can access the data in the array from within the function, but I cannot manipulate the data. I finally broke the whole problem down into as simple a solution as possible (hoping the compiler couldn't not understand what I intended). Here is the resulting code (and it doesn't work).

`uint64 TYPE_CONVERT_Uint8Array_to_Uint64( uint8* input ) {  // This assumes one sent the data in little-endian format  uint32 temp_LO = 0;  uint32 temp_HI = 0;  uint64 temp;    temp_HI |= (((uint32)input[7]) << 24);  temp_HI |= (((uint32)input[6]) << 16);  temp_HI |= (((uint32)input[5]) << 8);  temp_HI |= (((uint32)input[4]) << 0);  temp_LO |= (((uint32)input[3]) << 24);  temp_LO |= (((uint32)input[2]) << 16);  temp_LO |= (((uint32)input[1]) <<  8);     temp_LO |= (((uint32)input[0]) <<  0);    temp = (uint64)temp_HI;  temp = temp << 32;  temp |= temp_LO;    return( temp );  }`

After all this work, temp_HI and temp_LO have the correct values, but I cannot physically assign temp_HI to temp! How does an assignment like that not work? I always get back 0x00000000. So any point in continuing is moot.

Anyone have any suggestions?

• ###### 1. Re: Fascinating 64-Bit OR Failure

Here's an update. I dumbed it down a bit further so that I could shift the value in the 64-bit variable by 8 bits at a time (see code). Interestingly when I shift the last 8-bits (to get a full 32-bit shift), the value in the variable zeros.

`uint64 TYPE_CONVERT_Uint8Array_to_Uint64( uint8* input ) {  // This assumes one sent the data in little-endian format  uint32 temp_LO = 0;  uint32 temp_HI = 0;  uint64 temp = 0xFFFFFFFFFFFFFFFF;  //uint64 temp;    temp_HI |= (((uint32)input[7]) << 24);  temp_HI |= (((uint32)input[6]) << 16);  temp_HI |= (((uint32)input[5]) << 8);  temp_HI |= (((uint32)input[4]) << 0);  temp_LO |= (((uint32)input[3]) << 24);  temp_LO |= (((uint32)input[2]) << 16);  temp_LO |= (((uint32)input[1]) <<  8);     temp_LO |= (((uint32)input[0]) <<  0);    temp = (uint64)temp_HI;  temp = temp << 8;  temp = temp << 8;  temp = temp << 8;  temp = temp << 8; // last 8-bit shift fails...temp gets 0x0000000000000000  temp |= temp_LO;    return( temp );  }`
• ###### 2. Re: Fascinating 64-Bit OR Failure

i'm not near a development  pc right now. I'm pretty sure you are fighting a cast/conversion idiosyncrasy with C.

You need some more uint64 casts imho.

I'll  gen up a solution tomorrow, plus there is a union/cast solution i use instead. I'll demo it also.

Ed

• ###### 3. Re: Fascinating 64-Bit OR Failure

Before continuing any further tests: Be aware that there is a known debugger bug in displaying 64-bit variables. I suggest you to inspect the memory locations to see the values stored.

Bob