Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
void main()
{
 long n,dec,mult,r,base;
 clrscr();
 printf("\n Enter a base : ");
 scanf("%ld",&base);
 printf("\n Enter a number :");
 scanf("%ld",&n);
 dec = 0;
 mult=1;
 printf("\n Decimal equivalent of base %ld number %ld is ",base,n);
 while ( n != 0 )
 {
  r = n % 10;
  n /= 10;
  r = r * mult;
  dec = dec + r;
  mult *= base;
 } 
 printf("%ld",dec);}

this program converts the integer part of any number system of base 2, 8 &16 to decimal. please tell me wht command shld b given 2 calculate the fractional part also. i need it urgently plz help.
Posted
Updated 20-Sep-12 7:04am
v2
Comments
ridoy 20-Sep-12 13:07pm    
clear the question more..

1 solution

Each digit to the right of the decimal point is the reciprocal of the power of the base for that base. So for octal numbers the value 0.44 equates to
0
4 / 8  // .4
4 /64  // . 04
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900