I have a sample set of 32-bit data in the format 24-bit, 2’s complement, MSB first. The data precision is 18 bits; unused bits are zeros. I want to process the numbers in this sample set to find their average value.
However, I am not sure how to convert all the numbers to the same type and then use them for calculating the average.
One way is to bit shift all the numbers from the sample set to right by 14. This way I directly get the 18 useful bits (since it is 24-bit data with 18-bit precision, so extract only 18 useful bits). Then I can directly use these numbers to calculate their average.
Following is an example sample set of data samples:-
0xF9AFC000
0xF9AFC000
0xF9AE4000
0xF9AE0000
0xF9AE0000
0xF9AD0000
0xF9AC8000
0xF9AC8000
0xF9AC4000
0xF9AB4000
0xF9AB8000
0xF9AB4000
0xF9AA4000
0xF9AA8000
0xF9A98000
0xF9A8C000
0xF9A8C000
0xF9A8C000
0xF9A88000
0xF9A84000
However, the 18-bit number still has the sign bit (MSB). This bit is not always set and might be 0 or 1 depending upon the data.
Should I just mask the sign bit by &ing all the numbers with 0x1FFFF and use them for calculating average?
Or should I first convert them from 2's complement to integers by negating and adding 1?
Please suggest a proper way to extract and process "24-bit, 2’s complement, MSB first" number from a 32-bit number.
Thanks in advance!