Say I have the following code:
uint32_t fillThisNum(int16_t a, int16_t b, int16_t c){ uint32_t x = 0; uint16_t temp_a = 0, temp_b = 0, temp_c = 0; temp_a = a << 24; temp_b = b << 4; temp_c = c << 4; x = temp_a|temp_b|temp_c; return x; } Essentially what I'm trying to do is fill the 32-bit number with bit information that I can extract at a later time to perform different operations.
Parameter a would hold the first 24 bits of "data", b would hold the next 4 bits of "data" and c would hold the final 4 bits of "data".
I have a couple questions:
- Do the parameters have to be the same bit length as the function type, and must they be unsigned?
- Can I assign an unsigned int to a signed int? (i.e.
uint32_t a = int32_t b;) - Can I fill a 32-bit number with the 16-bit parameters so long they don't exceed the length of the 32-bit return value.
Any advice/tips/hints would be much appreciated, thank you.
intbit size is 16,temp_a = a << 24;is not well defined.x, since all of thetemps are 16-bit, and it overlapsbwithc.