I am trying to cast float to bitwise int in C. Here's my code snippet:
write_eeprom(INDEX_CONFIG_TEMPERATURE_OFFSET_HIGH_INT, (unsigned int) (temperature_offset>>16));
write_eeprom(INDEX_CONFIG_TEMPERATURE_OFFSET_LOW_INT, (unsigned int) (temperature_offset));
I am getting the following error:
error: invalid operands to binary >> (have 'float' and 'int'),
while trying to compile. Here, temperature_offset is a float type and I am trying to cast it as high int and low int as I am trying to save data in EEPROM in 16-bit chunks (as I am using a 16-bit microcontroller). I know that the '>>' does not apply to float types. How can I fix this issue? I tried using a separate unsigned int variable called temperature_offset_int and then I used memcpy to cast the float into it. However, my MPLAB IDE displays an error message 'unexpected token' when I use the following:
memcpy(&temperature_offset_int, &temperature_offset, sizeof temperature_offset);
Does anyone know a solution to this problem?