Convert uint16_t to int

3

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?

    
asked by anonymous 29.11.2017 / 04:27

1 answer

1

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.

    
29.11.2017 / 11:22