arthurtung

Untitled

Jul 22nd, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void enableFlushAfterPrintf()
  5. {
  6. setvbuf(stdout, 0, _IONBF, 0);
  7. setvbuf(stdin, 0, _IONBF, 0);
  8. }
  9. char int2hex(int intVal);
  10.  
  11. int main()
  12. {
  13. enableFlushAfterPrintf();
  14. int baseten=0;
  15. int conversion=0;
  16. int basevalue=0;
  17. int remainders=0;
  18. float quotient;
  19. int iVal;
  20. do
  21. {
  22. printf("Please enter a value from 0-1024, -1 to exit\n");
  23. scanf("%i", &baseten);
  24. if(baseten >1024)
  25. {
  26. printf("Please enter a value from 0-1024\n");
  27. }
  28. else if (baseten >0 && baseten <=1024)
  29. {
  30. printf("Please enter a value from 2-16\n");
  31. scanf("%i", &basevalue);
  32. while(baseten>0)
  33. {
  34. quotient=baseten/basevalue;
  35. remainders=baseten%basevalue;
  36. printf("%i\n", remainders);
  37. baseten=quotient;
  38.  
  39. quotient=int2hex(iVal);
  40. if(baseten=0)
  41. {
  42. break;
  43. }
  44.  
  45. }
  46.  
  47. printf("Value [%i] converted to base [%i]:\n", baseten, basevalue);
  48. printf("The resulting conversion string is %c\n", int2hex(iVal));
  49. }
  50. } while (baseten != -1);
  51.  
  52.  
  53. }
  54. char int2hex(int iVal)
  55. {
  56. char chVal;
  57. if((iVal>=0)&& (iVal<=9))
  58. {
  59. chVal='0'+iVal;
  60. }
  61. else if((iVal>=10)&& (iVal<=15))
  62. {
  63. chVal='A'+(iVal-10);
  64.  
  65. }
  66. else
  67. {
  68. chVal='.';
  69. }
  70. return chVal;
  71. }
Add Comment
Please, Sign In to add comment