I have a uint64 variable ...but the function in which I want to pass it only accepts uint32.
I tried using static unsigned int ToUInt32(uint64 variable); reference MSDN, but it gives an error that precision lost.
Is there any way to convert uint64 to uint32 without losing any data?
Well think about what you are trying to do. You are taking a number which will potentially take up to 64bits and then cutting in half. Of course you are going to lose data in this instance.
If you are sure that the number being given is not going to be larger than uint32 then you can try this
uint64 largeNumber = 9876543210;
uint32 smallNumber = largeNumber & 0xFFFFFFFF;
But this WILL lose you half of your number if it's bigger than 32bits.
No. You can't fit two gallons of water into a one-gallon container, and you can't fit 64 bits of data into a 32-bit value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With