hexadecimal to Decimal number

Please support our C++ advertiser: Intel Parallel Studio Home
sahasrara sahasrara is offline Offline Jan 8th, 2009, 8:36 pm |
0
Hi Hi Hi
this solution is inverse of other solution that changed Decimal number to hexadecimal . It changes hexadecimal number to Decimal !
There is the other way to change characters to numbers.

Good Luck!
Quick reply to this message  
C++ Syntax
  1. //16Radix number to Decimal
  2. //Programming by : Erfan Nasoori
  3. //Mail : ketn68@yahoo.com
  4. //Date of send : 2009/1/9
  5.  
  6. #include<iostream.h>
  7. #include<string.h>
  8. #include<math.h>
  9. #include<conio>
  10. void main()
  11. {
  12. int k=-1,j,i;
  13. double sum=0 ;
  14. int x[20];
  15. char hexa[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
  16. char s[20];
  17. cout<<"Number in 16 radix : ";
  18. cin>>s;
  19. for(i=0 ; s[i] ; ++i)
  20. if(s[i] >= 'a' && s[i] <= 'z')
  21. s[i] -= 32;
  22.  
  23. for(i=0 ; s[i] ; ++i)
  24. for(j=0 ; j<16 ; ++j)
  25. if(s[i] == hexa[j])
  26. {
  27. x[++k]=j;
  28. }
  29.  
  30. int y=strlen(s);
  31. for( i=(y-1) ,j=0 ; i>=0 ; --i , ++j)
  32. {
  33. sum += (pow(16,i)*x[j]);
  34. }
  35. cout<<"--------------------------------------------------"<<endl;
  36.  
  37. cout<<"Radix 10 = "<<sum;
  38. getch();
  39. }
0
William Hemsworth William Hemsworth is offline Offline | Jan 9th, 2009
- Wrong headers used
- 'void main' used
- getch() used
- Bad formatting

Try again.
 
0
sahasrara sahasrara is offline Offline | Jan 9th, 2009
Please.
I wrote it by Borland 5.02!!!!!
 
 

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC