944,147 Members | Top Members by Rank

Ad:
  • C++ Code Snippet
  • Views: 1711
  • C++ RSS
0

Convert Decimal to hexadecimal number

by on Jan 10th, 2009
This code converts decimal number to hexadecimal number
I wrote it by Borland 5.02 .

Good Luck
C++ Code Snippet (Toggle Plain Text)
  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:
Previous Thread in C++ Forum Timeline: Having trouble with rand();
Next Thread in C++ Forum Timeline: reccommend any books?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC