Arduino Uno & 24 Bit ADC - 2's Compliment to Binary conversion

I have an Arduino uno reading output values from a 24 bit adc ADS1231 I am able to get the data in 2’s compliment format as expected (datasheet attached page 12), but the problem is I would like it to be in Decimal format with a positive range as an example (0 to 20000) instead of (800000h to 7FFFFFh) and or at least initially a format like (-10000 to + 9999). Please help with how I could do this conversion. I know that 2’s compliment to Decimal this is what I have to do:

first check if the number is negative or positive by looking at the sign bit. If it is positive, simply convert it to decimal. If it is negative, make it positive by inverting the bits and adding one. Then, convert the result to decimal. The negative of this number is the value of the original binary. But how do I actually do this in an arduino platform c. To read the adc values at the moment I am using:

void readADS1231(void)
while(digitalRead(D_OUT));//WAIT UNTIL DATA IS READY
//24–>21 bits
clock ();
if(digitalRead(D_OUT)){adcvalue=adcvalue+0x800000;} //24
clock ();
clock ();
… etc

DATA SHEET ADS1231.pdf (912 KB)

Do you know the pulseIn() function of the Arduino environment?

The Arduino stores negative numbers in two's compliments too, so you can read in the value, extend to 32bit and convert it by pointer swapping or a union.

Thank you for your reply.

X = bit24 & adcvalue; // zero-ing the rest of the adcvalue bits except the sign bit.
if(X==bit24) // if sign bit is = 1
adcvalue_32bit = adcvalue+0xFF000000; // sign extend adc value to 32 bit
else // sign bit is = 0
adcvalue_32bit = adcvalue+0x00000000; // sign extend adc value to 32 bit

I have used this code to convert the 24 bit adc value to 32 bits which seems to work fine now if I press my sensor for positive push: (zero+offset) to 0x7FFFFF and (0+offset) to 0xFF8000000 for negative push.
24 bits for positive and 32 bit for negative which seems to be working as expected.
Now I just need to know how to convert this number to something more meaningful like instead of going from negative full scale 0xFF8000000 to 0 midpoint to 0x7FFFFF positive full scale. I would like to have it like 0 to X where 0 is equivalent to 0xFF8000000, X/2 is equivalent to midpoint and X is the postive full scale. How do I achieve this code?
ps. No I do not know about pulseln sorry

Is this what you're trying to do?

count=count^0x800000;         // convert 24 bit ADC two's comp output as follows

  // two's comp min =  0x800000 = -8388608; converted = 0
  // two's comp zero = 0x000000 =        0; converted = 2^23 = 8,388,608
  // two's comp max =  0x7FFFFF = +8388607; converted = (2^24)-1 = 16,777,215

PS: your post title is confusing... it says you want convert two's complement to BINARY. It seems you actually want to convert and shift two's comp to a positive DECIMAL. But your post is confusing as well. So who knows.......

Once you have sign-extended the 24-bit number to a 32-bit number, its range is from -8388608 to +8388607. Simply adding 8388608 to it converts it to the range from zero to 16777215.


Thank you all.
Problem solved!