How do i make a C program that would:
1.) Convert Binaries to Decimal
2.) Hexadecimal to Decimal
Really Hard for me to do, I am a really bad programmer, but i can understand the codes. Please help me, it would really help me if you give me the algorithm or the logic or codes to makes these possible.
How do i make a C program that will convert Binaries to Decimals? Im a really bad programmer i admit. T_T?
Here's some pseudo code for you.
Binary to decimal:
Set result D to 0
While binary digits are available {
Get next binary digit into B
D = D * 2 + B
}
D is the decimal result
Hex to decimal:
Set result D to 0
While hex digits are available {
Get next hex digit into H
D = D * 16 + H
}
D is the decimal result
Reply:here is a C pseudocode.
binary-to-decimal(int b)
{
for(i=b,j=0;i%26gt;=0;i/=10,++j) {
d = d+(i%10)*(2 raised to the power of j)
}
return d;
}
hexadecimal-to-decimal(char *h)
{
for(i=last letter of h,j=0; i is at the first letter or more; move i by one letter toward the first letter,++j) {
d = d+(int)i * (16 raised to the power of j);
}
return d;
}
homework? you gotta learn programming and C by yourself for your own sake.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment