This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

About "long" format

Hi. I have a question. I tested that nrf52 get datas from sensors. But the code was not moved well, I made code to test bit shift. Please see my code.

#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>

long a = 0;
a = (1< 24) | (2<< 16) | (4<< 8) | 8;
printf("%ld\r\n",a);
a = (0< 24) | (2<< 16) | (4<< 8) | 8;
printf("%ld\r\n",a);
a = (0< 24) | (0<< 16) | (0<< 8) | 0;
printf("%ld\r\n",a);

The code output, 132105 132105 1

I think 32-24bit are not used, and after shift_expression, data is added 1.

What cause it?

Please tell me.

Related