Howdy, Stranger!

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

Categories

BCD to Dec and vice versa

southern_ladsouthern_lad Member Posts: 21
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

  • southern_ladsouthern_lad Member Posts: 21
    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;
    : }
    :

  • Andre YoungAndre Young USAMember Posts: 0

    ____ // http://forcoder.org // free ebooks and video tutorials about || Delphi, Ruby, C#, Swift, MATLAB, Scratch, Assembly, Visual Basic .NET, Go, Objective-C, Python, Visual Basic, Perl, R, JavaScript, PHP, Java, PL/SQL, C, C++ F#, FoxPro, Julia, Erlang, ML, Scala, ABAP, Lisp, Crystal, Awk, SAS, Rust, Kotlin, Fortran, Prolog, LabVIEW, COBOL, Logo, Clojure, VBScript, Lua, Scheme, Bash, Apex, D, Dart, Hack, Transact-SQL, Ada, Alice ||

Sign In or Register to comment.