5
I’m doing a project where a distance detector stores the distance in a variable uint16_t
, and I need to turn it into int
to make comparisons, but I can find nowhere how to do it. How to do?
5
I’m doing a project where a distance detector stores the distance in a variable uint16_t
, and I need to turn it into int
to make comparisons, but I can find nowhere how to do it. How to do?
4
One fits the other perfectly and a promotion is done automatically. Look what simple:
#include <stdio.h>
#include <inttypes.h>
int main(void) {
uint16_t x = 1000;
int y = x;
printf("%d", y);
}
See working on ideone. And in the repl it.. Also put on the Github for future reference.
Browser other questions tagged c typing type-conversion int
You are not signed in. Login or sign up in order to post.
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero