Advertisement
arthurtung

Untitled

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