0

hi i am making a Bcd to Binary conversion can somebody help me lessen the code? thanks.

//! Converts a two-byte, 3-digit, BCD number into a binary value.
extern uint16_t BcdBin( const uint8_t* const pBcdBin);

//uint16_t BcdBin(const uint8_t * const pBcdBin)

int main()
{
int Num;
int A=0,B=0,C,D,E=1;
int F[100];



printf("Enter the number :");
scanf("%d",&Num);


while(Num>0)

{

A=Num%2;

F[B]=A;

Num=Num/2;

B++;

}

if(B<4)

{
       C=B;

for(D=1;D<=4-C;D++)

{

F[B]=0;

B++;
}
}

if(B>4)

{

for(D=0;D<B;D++)

{ if(E==4)

E=1;
else

E++;
}
E--;
if(E<4)
{ for(D=1;D<=4-E;D++)

{
F[B]=0;

B++;

}
}

}

for(E=1,D=B-1;D>=0;D--,E++)

{ printf("%d",F[D]);

if(E==4)

{ printf(" ");

E=0;
}

}

getch();

}
2
Contributors
1
Reply
3
Views
4 Years
Discussion Span
Last Post by WaltP
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.