I'm doing a project where a distance detector stores distance in a uint16_t
variable, and I need to turn it into int
to make the comparisons, but I can not find anywhere how to do this. How to do?
I'm doing a project where a distance detector stores distance in a uint16_t
variable, and I need to turn it into int
to make the comparisons, but I can not find anywhere how to do this. How to do?
One fits into the other perfectly and a promotion is done automatically. Look how simple:
#include <stdio.h>
#include <inttypes.h>
int main(void) {
uint16_t x = 1000;
int y = x;
printf("%d", y);
}
See working at ideone . And no Coding Ground . Also I put GitHub for future reference.