bcd to binary
Discussion in "8051 Discussion Forum" started by sharath411 Jun 18, 2011.
Fri Jun 24 2011, 11:38 pm
@Sharath, No - but you can use this C code to learn the method, and then convert it to assembly yourself. (note: This code will convert 8 digits, and does not contain any error checking - you should add that to your code to be sure )
I've separated out the individual steps into i1, i2, and i3 so you can see the values in your debugger...
Hope this helps,
I've separated out the individual steps into i1, i2, and i3 so you can see the values in your debugger...
void BCD32BIN32( uint32_t *in, uint32_t *out ) { uint8_t i; uint32_t i1, i2, i3, mask = 0xF0000000; *out = 0x00000000; // 32 bits = 8 possible BCD values... for( i=0; i<8; i++ ) { i1 = *in & mask; i2 = (7-i)*4; i3 = i1> > i2; *out += i3; // no need to multiply on units digit... if( i == 7 ) break; *out *= 10; mask = mask > > 4; } } void main( void ) { uint32_t TestValue = 0x12345678; uint32_t ReturnValue; // TestValue has the BCD value in it... // Return Value is the binary equivalent... // ----------------------------------------- BCD32BIN32( &TestValue, &ReturnValue ); while(1); }
Hope this helps,
[ Edited Mon Jun 27 2011, 03:28 am ]
Powered by e107 Forum System