I have a basic C question.
Suppose I've declared and initialized a standard 16 bit unsigned integer
uint16_t var1 = 0x1234;
and then suppose I declared an 8 bit unsigned integer:
uint8_t var2;
If I were to assign,
var2 = var1;
would this be a valid statement? And would it simply truncate the more significant bits yielding a result such that:
var2 == 0x34
evaluates to true?
Yes. The compiler would internally interpret this as
which would result in var2 having the value 0x34.
I think you mean:
Yes, this will truncate
var1
to fit withinvar1
's data type, sovar2
will be equal to 0x34.