Dear support
I need to pass 128 bits service uuid to discovery process as variable, I have an array of 16 bytes of uuid number, it is divided into five parts as show here
Dear support
I need to pass 128 bits service uuid to discovery process as variable, I have an array of 16 bytes of uuid number, it is divided into five parts as show here
Hi,
The compiler (gcc in my test) should warn you when an overflow occurs, like in this case:
warning: left shift count >= width of type [-Wshift-count-overflow] 15 | w48 = (value[10]<<40) + (value[11]<<32); //this line ends up 0 | ^~ warning: left shift count >= width of type [-Wshift-count-overflow] 15 | w48 = (value[10]<<40) + (value[11]<<32); //this line ends up 0
Can you try casting value[10] and [11] to uint64_t to see if this fixes the issue?
Kind regards,
Håkon
Hi,
The compiler (gcc in my test) should warn you when an overflow occurs, like in this case:
warning: left shift count >= width of type [-Wshift-count-overflow] 15 | w48 = (value[10]<<40) + (value[11]<<32); //this line ends up 0 | ^~ warning: left shift count >= width of type [-Wshift-count-overflow] 15 | w48 = (value[10]<<40) + (value[11]<<32); //this line ends up 0
Can you try casting value[10] and [11] to uint64_t to see if this fixes the issue?
Kind regards,
Håkon
thank you, Hakon
Casting individual value[10] and value[11] works, but not overall result, my compiler doesn't give out any warnings.
Ping
Hi Ping,
Can you share the content of the value[10..15] as well as the full content of "w48"?
PingISTL said:Casting individual value[10] and value[11] works, but not overall result, my compiler doesn't give out any warnings.
I'm not sure what you mean, were you able to successfully populate the upper 32 bits ?
Kind regards,
Håkon
Sorry for that, I didn't make myself clear, your solution works. code as below:
w48 = ((uint64_t)Val[14]<<8)+(uint64_t)Val[15]; w48 += ((uint64_t)Val[12]<<24)+((uint64_t)Val[13]<<16); w48 += ((uint64_t)Val[10]<<40)+((uint64_t)Val[11]<<32);
Thank you!
Ping