Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- void enableFlushAfterPrintf()
- {
- setvbuf(stdout, 0, _IONBF, 0);
- setvbuf(stdin, 0, _IONBF, 0);
- }
- char int2hex(int intVal);
- int main()
- {
- enableFlushAfterPrintf();
- int baseten = 0;int basevalue = 0;int remainders = 0;int quotient;char conversion;
- do
- {
- printf("Please enter a value from 0-1024, -1 to exit\n");
- scanf("%i", &baseten);
- if (baseten > 1024)
- {
- printf("Please enter a value from 0-1024\n");
- }
- else if (baseten > 0 && baseten <= 1024)
- {
- printf("Please enter a value from 2-16\n");
- scanf("%i", &basevalue);
- if (baseten > 0)
- {
- quotient = baseten / basevalue;
- remainders = baseten % basevalue;
- printf("Remainder is %i,", remainders);
- baseten = quotient;
- printf("Quotient is %i, %i,", quotient, quotient);
- printf("The resulting conversion string is \n%c\n%c\n",
- int2hex(quotient), int2hex(quotient));
- }
- }
- } while (baseten != -1);
- }
- char int2hex(int iVal)
- {
- char chVal;
- if ((iVal >= 0) && (iVal <= 9))
- {
- chVal = '0' + iVal;
- }
- else if ((iVal >= 10) && (iVal <= 15))
- {
- chVal = 'A' + (iVal - 10);
- }
- else
- {
- chVal = '.';
- }
- return chVal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement