Convert Decimal to hexadecimal number

Please support our C++ advertiser: Intel Parallel Studio Home
sahasrara sahasrara is offline Offline Jan 10th, 2009, 4:31 pm |
0
This code converts decimal number to hexadecimal number
I wrote it by Borland 5.02 .

Good Luck
Quick reply to this message  
C++ Syntax
  1. //Decimal to hexadecimal number
  2. //programming by : Erfan Nasoori
  3. //Date of send : 2009/1/11
  4.  
  5. #include <iostream.h>
  6.  
  7. void main()
  8. {
  9. int x,y,i;
  10. int d,n=1;
  11. int * r;
  12. char h[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
  13.  
  14. cout<<"Enter x : ";
  15. cin>>x;
  16. y=x;
  17. while(x >= 10)
  18. {
  19. x/=10;
  20. ++n;
  21. }
  22. r=new int[n];
  23. for(i=0 ; y >= 16 ; ++i)
  24. {
  25. r[i]=y%16;
  26. y /= 16;
  27. }
  28. r[i++]=y;
  29.  
  30. cout<<"16 base = ";
  31. for(i=(n-1) ; i>=0 ; --i)
  32. {
  33. cout<<h[r[i]];
  34. }
  35. cin.get();
  36. }

Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC