| | |
Convert Decimal to Radix
Thread Solved |
•
•
Join Date: Sep 2009
Posts: 17
Reputation:
Solved Threads: 0
C Syntax (Toggle Plain Text)
#include <stdio.h> #define SIZE 25 int main(void) { int d, b; printf("Enter decimal and base: "); scanf("%d", &d); scanf("%d", &b); if(b<2){ printf("Your base is too low! \n"); } else if (b >16){ printf("Your base is too high! \n"); } else if(d==0){ printf("%d \n", 0); } else{ while (d!=0){ char temp[SIZE]; char result[SIZE]; int i, r, n ; r = d%b; d = d/b; char basechars[] = "0123456789ABCDEF"; temp[i++] = basechars[r]; result[n++] = temp[--i]; printf("%c", result); } } system("PAUSE"); }
Last edited by Kombat; Sep 17th, 2009 at 6:16 pm.
You're making this more difficult than it needs to be. Look at this code snippet:
C Syntax (Toggle Plain Text)
while (d != 0) { r = d % b; d = d / b; result[len++] = basechars[r]; } for (i = len-1; i >= 0; --i) { printf("%c", result[i]); }
Last edited by yellowSnow; Sep 17th, 2009 at 8:26 pm.
Manic twiddler of bits
![]() |
Similar Threads
- convert Decimal to Hexadecimal system.. (C)
- Convert decimal to binary number? (Assembly)
- how to convert decimal value as string input to its hex equivalent (Assembly)
- Convert decimal to binary number? (Assembly)
- how to convert decimal to binary (C++)
- Convert decimal to binary and with base the 8 (C)
- How to convert a decimal number into its binary equivalent (Python)
Other Threads in the C Forum
- Previous Thread: Previous declaration of ___ was here
- Next Thread: c prgrams
| Thread Tools | Search this Thread |
#include adobe api array asterisks binarysearch calculate char cm copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fflush fgets file fork forloop frequency getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling segmentationfault sequential shape socket socketprograming stack standard string systemcall threads turboc unix user voidmain() wab win32api windows.h






