arthurtung

Untitled

Jul 22nd, 2016
36
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[100]={0};
  18. float quotient;
  19. do
  20. {
  21. printf("Please enter a value from 0-1024, -1 to exit\n");
  22. scanf("%i", &baseten);
  23. if(baseten >1024)
  24. {
  25. printf("Please enter a value from 0-1024\n");
  26. }
  27. else if (baseten >0 && baseten <=1024)
  28. {
  29. printf("Please enter a value from 2-16\n");
  30. scanf("%i", &basevalue);
  31. while(baseten>0)
  32. {
  33. quotient=baseten/basevalue;
  34. remainders=baseten%basevalue;
  35. printf("%i", remainders)
  36. baseten=quotient;
  37. if(baseten=0)
  38. {
  39. break;
  40. }
  41.  
  42. }
  43.  
  44. printf("Value [%i] converted to base [%i]:", baseten, basevalue);
  45. printf("The resulting conversion string is %i%i", quotient, remainders);
  46. }
  47. } while (baseten != -1);
  48.  
  49.  
  50. }
  51. char int2hex(int iVal)
  52. {
  53. char chVal;
  54. if((iVal>=0)&& (iVal<=9))
  55. {
  56. chVal='0'+iVal;
  57. }
  58. else if((iVal>=10)&& (iVal<=15))
  59. {
  60. chVal='A'+(iVal-10);
  61.  
  62. }
  63. else
  64. {
  65. chVal='.';
  66. }
  67. return chVal;
  68. }
Add Comment
Please, Sign In to add comment