Assign uint8_t int

0

I'm getting data and in my project saving in an array of uint8_t and then processing in int variable, okay I could leave everything int but this does not apply to the project.

int main()
{
    uint8_t data=0x13;
    int range=(int) data;

    printf("8 bits: %x\n", data); // Mostra 13
    printf("16 bits: %d\n", range); // Mostra 19

    return 0;
}

How can I assign 13 (uint8_t) to an int variable without it doing the conversion?

    
asked by anonymous 13.11.2018 / 23:23

1 answer

0

What you did was, the first printf you printed as hexadecimal and the second you printed as decimal.

13 in hexadecimal equals 19 in decimal.

There was no truncation of the value of the variable.

uint8_t (1 byte) fits fully into a int (4 bytes)

    
13.11.2018 / 23:46