CIR data is too large

Hello, I had a problem getting the CIR data

here is my code & result (acc CIR data)

Code:
static uint8_t CIR_data[6097];

                int32_t real_CIR[1016];

                dwt_readaccdata(CIR_data, 6097, 0);

                int j = 0;
                for(int i=1; i<6097; i+=6){
                	real_CIR[j] = ((CIR_data[i+2]) << 16 | (CIR_data[i+1]) << 8 | (CIR_data[i])) & 0x3ffff;
                	printf("%d,",real_CIR[j]);
                	Sleep(0.001);
                	j++;
                }

Result:

Output data(real part) joy: :joy:
Low : 218 (0xda)
Mid : 254 (0xfe)
High : 255 (0xff) so, → 11111111 11111110 11011010 → 111111111011011010 (18bit)

I read 1016 CIR samples and created a CIR real value array that excluding the upper 6 bits of the real part, but the values are too large.

Much thanks!

From the manual “Each value is actually 18-bit precision, with the upper 6-bits being all zero or ones depending on the sign of the value.”
In other words it’s 18 bit signed data padded to 24 bits. If you want to convert that to a 32 bit signed integer then you need to extend the sign bit.
Try:

real_CIR[j] = ((CIR_data[i+2]) << 16 | (CIR_data[i+1]) << 8 | (CIR_data[i]))
if (real_CIR[j] & 0x00800000)
  real_CIR[j] |= 0xff000000;

Thank you AndyA

I will try :joy: