uint32_t to int32_t conversion help needed

Hi everyone,

today I did some tests with a sensor in temperatures below 0 Celsius.

Unfortunately I made the mistake in declaring the temperature variable with uint32_t instead of int32_t.

Arduino shows these 3 measurements:

167771.20
167771.18
167770.95

Can anyone tell me what minus values these are? It should be somewhere around -1 Celsius or so.

Thanks.

Leo

Read this: http://arduino.cc/forum/index.php/topic,97455.0.html

You'll have to post some code as 167771.20 is neither an unsigned or signed integer.

You are correct. The ones I posted are converted to float values (/100).

The int vlaues are:

16777120
16777118
16777095

Sorry about that.

If the values you posted are unsigned and you need signed, then there is no conversion. 16777120 will not overflow a signed 32-bit int. Which also means the reverse is true.

Thank you very much for the help and opening my eyes!

I am now realizing that it's a lot more complicated than I had thought.

I'm going to reverse engineer my code to find the correct value.

If that doesn't work then no big deal. It was only a "nice to have" for knowing.

I found the error in my code which is the most important thing.

Thanks again.

I'm going to reverse engineer my code to find the correct value.

Why?

Unfortunately I made the mistake in declaring the temperature variable with uint32_t instead of int32_t.

So, fix the mistake.

the numbers sound like a 24 bit int - can that be possible?
Can you tell more about the sensor ?
Link datasheet?

16777216 = 2^24
=>
16777120 = -96
16777118 = -98
16777095 = -121

If the number is to be interpreted with 2 decimals it would be -0.96, -0.98, -1.21 which looks like a stable T measurement

Post your code if you need help with reverse engineering,

PaulS:

I'm going to reverse engineer my code to find the correct value.

Why?

Because I'm nosey.

PaulS:

Unfortunately I made the mistake in declaring the temperature variable with uint32_t instead of int32_t.

So, fix the mistake.

There is a saying: "He who can read has a clear advantage"

This thread isn't to long. Give it a try.

robtillaart:
the numbers sound like a 24 bit int - can that be possible?
Can you tell more about the sensor ?
Link datasheet?

16777216 = 2^24
=>
16777120 = -96
16777118 = -98
16777095 = -121

If the number is to be interpreted with 2 decimals it would be -0.96, -0.98, -1.21 which looks like a stable T measurement

Post your code if you need help with reverse engineering,

Thanks Rob. I think you may have goten it! I will verify.

Again, knowing the values was only a "nice to know" for me. I've already corrected my code. Problem is sovled.

Case closed.

Rob, if I could I'd send you some Bavarian beer.

I just verified your numbers with my code -> Bull's-eye :slight_smile:

Thanks!

Rob, if I could I'd send you some Bavarian beer.

I'll drink one here on your health,

Still open question:
Can you tell more about the sensor ? I really want to know what does 24 bit :slight_smile:
Link datasheet?