Im using this code taken from the mbed forum created by Kim Sec Tee:
//ch0.
cs=0; //cs low. start data collection
_spi.write(0x01); //write start bit. Not expecting return
_data1=_spi.write(0x80); //write control bit, expecting return B9, B8
_data2=_spi.write(0x00); //write anything, expecting return B7-B0
int ch0 =(_data1<<8) | _data2; //merge two 8bits data becoming 16bits data
ch0 = ch0 & 0x03FF; // mask off bit15 - bit10
cs=1; //cs high. end of data collection
(full code here: http://mbed.org/forum/mbed/topic/534/)
So I want to take the value stored in ch0 and change it into a decimal number for manipulation! From what I understand of the code the value stored in ch0 is in binary is this correct?
After some more research after posting yesterday I found a method to convert the binary to decimal. You take the first bit and times it by one second bit and times it by two ect. The thing im stuck on with this method is how you separate each of the bits from each other!?
Can anybody point me in the direction of some code to perform binary to decimal conversion!?