arthurtung

Untitled

Jul 22nd, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 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. int2hex=quotient;
  39. if(baseten=0)
  40. {
  41. break;
  42. }
  43.  
  44. }
  45.  
  46. printf("Value [%i] converted to base [%i]:\n", baseten, basevalue);
  47. printf("The resulting conversion string is %i\n", int2hex);
  48. }
  49. } while (baseten != -1);
  50.  
  51.  
  52. }
  53. char int2hex(int iVal)
  54. {
  55. char chVal;
  56. if((iVal>=0)&& (iVal<=9))
  57. {
  58. chVal='0'+iVal;
  59. }
  60. else if((iVal>=10)&& (iVal<=15))
  61. {
  62. chVal='A'+(iVal-10);
  63.  
  64. }
  65. else
  66. {
  67. chVal='.';
  68. }
  69. return chVal;
  70. }
Add Comment
Please, Sign In to add comment