BCD to Dec and vice versa

I have a fun which converts bcd 2 dec but am kinda like hoping there is a 'cleaner' way?

and what about the other way, can i just use / and then %?

Thankx


unsigned char Scr_16_01::BCD_TO_Decimal(unsigned char convert)
{
unsigned char decimal = convert&0x0f;
int temp=0;
printf("entered conversion function
");

if(convert&0x10)
decimal+=10;
if(convert&0x20)
decimal+=20;
if(convert&0x40)
decimal+=40;
if(convert&0x80)
decimal+=80;
return convert;
}

Comments

  • Hi,
    Cannone of u guys help with this?


    : I have a fun which converts bcd 2 dec but am kinda like hoping there is a 'cleaner' way?
    :
    : and what about the other way, can i just use / and then %?
    :
    : Thankx
    :
    :
    : unsigned char BCD_TO_Decimal(unsigned char convert)
    : {
    : unsigned char decimal = convert&0x0f;
    : int temp=0;
    : printf("entered conversion function
    ");
    :
    : if(convert&0x10)
    : decimal+=10;
    : if(convert&0x20)
    : decimal+=20;
    : if(convert&0x40)
    : decimal+=40;
    : if(convert&0x80)
    : decimal+=80;
    : return convert;
    : }
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion