Decimal system to Binary, Octal and Hexadecimal system Conversion..

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jan 2008
Posts: 15
Reputation: campuzcrazyness is an unknown quantity at this point 
Solved Threads: 0
campuzcrazyness's Avatar
campuzcrazyness campuzcrazyness is offline Offline
Newbie Poster

Decimal system to Binary, Octal and Hexadecimal system Conversion..

 
0
  #1
Jul 19th, 2008
  1. #include <stdio.h>
  2.  
  3.  
  4. main()
  5. {
  6.  
  7. int ctr, bin, quotient, deci=0, binary,octal,hexa;
  8. float rem;
  9. char mark_magic;
  10.  
  11. clrscr();
  12.  
  13. do
  14. {
  15. clrscr();
  16. quotient = 1;
  17. binary = 1;
  18.  
  19. gotoxy(32,3); printf("-=< MAIN MENU >=-");
  20. gotoxy(15,5); printf("from any Number System to Decimal System conversion");
  21. gotoxy(5,6); printf("------------------------------------------------------------------------");
  22. gotoxy(5,7); printf("------------------------------------------------------------------------");
  23. gotoxy(26,9); printf("[A] Binary System");
  24. gotoxy(26,11); printf("[B] Octal System");
  25. gotoxy(26,13); printf("[C] Hexadecimal System");
  26. gotoxy(26,15); printf("[X] Exit");
  27. gotoxy(26,21); printf("what's your choice?: ");
  28.  
  29. mark_magic = getche();
  30.  
  31. clrscr();
  32.  
  33.  
  34. switch(toupper(mark_magic))
  35.  
  36. {
  37. case 'A':
  38. clrscr();
  39.  
  40. gotoxy(10,5); printf("########^_^ Convert Decimal system to Binary system ^_^########");
  41. gotoxy(5,6); printf("------------------------------------------------------------------------");
  42. gotoxy(5,7); printf("------------------------------------------------------------------------");
  43. binary = 2;
  44.  
  45. gotoxy(28,9);printf("enter decimal number: ");
  46.  
  47. scanf("%d",&deci);
  48.  
  49.  
  50. quotient = deci / binary;
  51.  
  52.  
  53.  
  54. for(bin=1;bin>=15;bin++)
  55. {
  56. bin = deeci%2;
  57. gotoxy(28,11);printf("Equivalent in Binary is %.0f",bin);
  58. }
  59.  
  60. gotoxy(51,24); printf("press any key to exit: ");
  61.  
  62.  
  63. getche();
  64. clrscr();
  65. break;
  66.  
  67. case 'B':
  68. clrscr();
  69.  
  70. gotoxy(10,5); printf("########^_^ Convert Decimal system to Octal system ^_^########");
  71. gotoxy(5,6); printf("------------------------------------------------------------------------");
  72. gotoxy(5,7); printf("------------------------------------------------------------------------");
  73. octal = 8;
  74.  
  75.  
  76. gotoxy(28,9);printf("enter decimal number: ");
  77.  
  78. scanf("%d",&deci);
  79.  
  80. for (ctr = 1; ctr<=deci; ctr++)
  81.  
  82. quotient = deci / octal;
  83.  
  84. gotoxy(28,11);printf("Equivalent in Octal is %d",quotient);
  85.  
  86.  
  87. gotoxy(51,24); printf("press any key to exit: ");
  88.  
  89. getche();
  90. break;
  91.  
  92. case 'C':
  93.  
  94. clrscr();
  95.  
  96. gotoxy(10,5); printf("########^_^ Convert Decimal system to Hexadecimal system ^_^########");
  97. gotoxy(5,6); printf("------------------------------------------------------------------------");
  98. gotoxy(5,7); printf("------------------------------------------------------------------------");
  99. hexa = 16;
  100.  
  101. gotoxy(28,9);printf("enter decimal number: ");
  102.  
  103. scanf("%d",&deci);
  104.  
  105. for (ctr = 1; ctr<=deci; ctr++)
  106.  
  107. quotient = deci / hexa;
  108.  
  109. gotoxy(28,11);printf("Equivalent in Hexadecimal is %d",quotient);
  110.  
  111. gotoxy(51,24); printf("press any key to exit: ");
  112.  
  113. getche();
  114. break;
  115.  
  116. }
  117. }
  118. while(toupper(mark_magic) != 'X');
  119.  
  120. }


this was rejected by my teacher,she said a lot of codes is missing. the problem is, I don't know what i'm going to write coz im new with C. Can you pls. help me with my problem?

thanks a lot!
Last edited by ~s.o.s~; Jul 19th, 2008 at 2:55 am. Reason: Added code tags, learn to use them.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 79
Reputation: Adak is an unknown quantity at this point 
Solved Threads: 7
Adak Adak is offline Offline
Junior Poster in Training

Re: Decimal system to Binary, Octal and Hexadecimal system Conversion..

 
0
  #2
Jul 19th, 2008
When you run a program and the first choice shows nothing, it's safe to say it's lacking!

I re-worked Choice A, but the answer is being written out in reverse. You need to take the digits and first put them into a small array or LIFO buffer of some kind, and print them out from that array or buffer in last in, first out, ourder, so when the number is 3, the zero's are all printed out before the 1's.

Always highlight your code you want to post on the forum, and press the # sign, so it will be made to look more like code, and not regular forum text.

  1. #include <stdio.h>
  2.  
  3.  
  4. int main() {
  5. int ctr, bin, quotient, deci=0, binary,octal,hexa, gar;
  6. float rem;
  7. char mark_magic;
  8.  
  9. do {
  10. clrscr();
  11. quotient = 1;
  12. binary = 1;
  13.  
  14. gotoxy(32,3); printf("-=< MAIN MENU >=-");
  15. gotoxy(15,5); printf("from any Number System to Decimal System conversion");
  16. gotoxy(5,6); printf("------------------------------------------------------------------------");
  17. gotoxy(5,7); printf("------------------------------------------------------------------------");
  18. gotoxy(26,9); printf("[A] Binary System");
  19. gotoxy(26,11); printf("[B] Octal System");
  20. gotoxy(26,13); printf("[C] Hexadecimal System");
  21. gotoxy(26,15); printf("[X] Exit");
  22. gotoxy(26,21); printf("what's your choice?: ");
  23.  
  24. mark_magic = getche();
  25. clrscr();
  26. switch(toupper(mark_magic)) {
  27. case 'A':
  28. clrscr();
  29. gotoxy(10,5); printf("########^_^ Convert Decimal system to Binary system ^_^########");
  30. gotoxy(5,6); printf("------------------------------------------------------------------------");
  31. gotoxy(5,7); printf("------------------------------------------------------------------------");
  32. binary = 2;
  33. gotoxy(28,9);printf("enter decimal number: ");
  34.  
  35. scanf("%d",&deci);
  36. quotient = deci / binary;
  37. gotoxy(28,11);printf("Equivalent in Binary is ");
  38. for(bin=1; bin <=16; bin++) {
  39. printf("%d",deci % 2);
  40. deci = deci / 2;
  41. }
  42.  
  43. gotoxy(51,24); printf("press any key to exit: ");
  44. getche();
  45. clrscr();
  46. break;
  47.  
  48. case 'B':
  49. clrscr();
  50. gotoxy(10,5); printf("########^_^ Convert Decimal system to Octal system ^_^########");
  51. gotoxy(5,6); printf("------------------------------------------------------------------------");
  52. gotoxy(5,7); printf("------------------------------------------------------------------------");
  53. octal = 8;
  54. gotoxy(28,9);printf("enter decimal number: ");
  55. scanf("%d",&deci);
  56. for (ctr = 1; ctr<=deci; ctr++)
  57. quotient = deci / octal;
  58. gotoxy(28,11);printf("Equivalent in Octal is %d",quotient);
  59. gotoxy(51,24); printf("press any key to exit: ");
  60. getche();
  61. break;
  62. case 'C':
  63. clrscr();
  64. gotoxy(10,5); printf("########^_^ Convert Decimal system to Hexadecimal system ^_^########");
  65. gotoxy(5,6); printf("------------------------------------------------------------------------");
  66. gotoxy(5,7); printf("------------------------------------------------------------------------");
  67. hexa = 16;
  68. gotoxy(28,9);printf("enter decimal number: ");
  69. scanf("%d",&deci);
  70. for (ctr = 1; ctr<=deci; ctr++)
  71. quotient = deci / hexa;
  72. gotoxy(28,11);printf("Equivalent in Hexadecimal is %d",quotient);
  73. gotoxy(51,24); printf("press any key to exit: ");
  74. getche();
  75. break;
  76.  
  77. }
  78. }while(toupper(mark_magic) != 'X');
  79. gar = getchar(); gar++;
  80. return 0;
  81. }
  82.  
  83.  
  84. /*this was rejected by my teacher,she said a lot of codes is missing. the problem is, I don't know what i'm going to write coz im new with C. Can you pls. help me with my problem?
  85. thanks a lot!
  86. */
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Decimal system to Binary, Octal and Hexadecimal system Conversion..

 
0
  #3
Jul 19th, 2008
Step 1 would be to remove ALL the gotoxy() and clrscr() and any other decorative features until you've actually got the damn thing to work.

Adding eye candy to an already working program is trivial, compared with trying to maintain it whilst you're debugging the code.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 25
Reputation: adarshcu is an unknown quantity at this point 
Solved Threads: 4
adarshcu adarshcu is offline Offline
Light Poster

Re: Decimal system to Binary, Octal and Hexadecimal system Conversion..

 
0
  #4
Jul 20th, 2008
a goto statement isnt tat good for programming..
avoid it if possible..
this program becomes pretty simple without em..
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 15
Reputation: campuzcrazyness is an unknown quantity at this point 
Solved Threads: 0
campuzcrazyness's Avatar
campuzcrazyness campuzcrazyness is offline Offline
Newbie Poster

Re: Decimal system to Binary, Octal and Hexadecimal system Conversion..

 
0
  #5
Jul 21st, 2008
Originally Posted by Adak View Post
When you run a program and the first choice shows nothing, it's safe to say it's lacking!

I re-worked Choice A, but the answer is being written out in reverse. You need to take the digits and first put them into a small array or LIFO buffer of some kind, and print them out from that array or buffer in last in, first out, ourder, so when the number is 3, the zero's are all printed out before the 1's.

Always highlight your code you want to post on the forum, and press the # sign, so it will be made to look more like code, and not regular forum text.

  1. #include <stdio.h>
  2.  
  3.  
  4. int main() {
  5. int ctr, bin, quotient, deci=0, binary,octal,hexa, gar;
  6. float rem;
  7. char mark_magic;
  8.  
  9. do {
  10. clrscr();
  11. quotient = 1;
  12. binary = 1;
  13.  
  14. gotoxy(32,3); printf("-=< MAIN MENU >=-");
  15. gotoxy(15,5); printf("from any Number System to Decimal System conversion");
  16. gotoxy(5,6); printf("------------------------------------------------------------------------");
  17. gotoxy(5,7); printf("------------------------------------------------------------------------");
  18. gotoxy(26,9); printf("[A] Binary System");
  19. gotoxy(26,11); printf("[B] Octal System");
  20. gotoxy(26,13); printf("[C] Hexadecimal System");
  21. gotoxy(26,15); printf("[X] Exit");
  22. gotoxy(26,21); printf("what's your choice?: ");
  23.  
  24. mark_magic = getche();
  25. clrscr();
  26. switch(toupper(mark_magic)) {
  27. case 'A':
  28. clrscr();
  29. gotoxy(10,5); printf("########^_^ Convert Decimal system to Binary system ^_^########");
  30. gotoxy(5,6); printf("------------------------------------------------------------------------");
  31. gotoxy(5,7); printf("------------------------------------------------------------------------");
  32. binary = 2;
  33. gotoxy(28,9);printf("enter decimal number: ");
  34.  
  35. scanf("%d",&deci);
  36. quotient = deci / binary;
  37. gotoxy(28,11);printf("Equivalent in Binary is ");
  38. for(bin=1; bin <=16; bin++) {
  39. printf("%d",deci % 2);
  40. deci = deci / 2;
  41. }
  42.  
  43. gotoxy(51,24); printf("press any key to exit: ");
  44. getche();
  45. clrscr();
  46. break;
  47.  
  48. case 'B':
  49. clrscr();
  50. gotoxy(10,5); printf("########^_^ Convert Decimal system to Octal system ^_^########");
  51. gotoxy(5,6); printf("------------------------------------------------------------------------");
  52. gotoxy(5,7); printf("------------------------------------------------------------------------");
  53. octal = 8;
  54. gotoxy(28,9);printf("enter decimal number: ");
  55. scanf("%d",&deci);
  56. for (ctr = 1; ctr<=deci; ctr++)
  57. quotient = deci / octal;
  58. gotoxy(28,11);printf("Equivalent in Octal is %d",quotient);
  59. gotoxy(51,24); printf("press any key to exit: ");
  60. getche();
  61. break;
  62. case 'C':
  63. clrscr();
  64. gotoxy(10,5); printf("########^_^ Convert Decimal system to Hexadecimal system ^_^########");
  65. gotoxy(5,6); printf("------------------------------------------------------------------------");
  66. gotoxy(5,7); printf("------------------------------------------------------------------------");
  67. hexa = 16;
  68. gotoxy(28,9);printf("enter decimal number: ");
  69. scanf("%d",&deci);
  70. for (ctr = 1; ctr<=deci; ctr++)
  71. quotient = deci / hexa;
  72. gotoxy(28,11);printf("Equivalent in Hexadecimal is %d",quotient);
  73. gotoxy(51,24); printf("press any key to exit: ");
  74. getche();
  75. break;
  76.  
  77. }
  78. }while(toupper(mark_magic) != 'X');
  79. gar = getchar(); gar++;
  80. return 0;
  81. }
  82.  
  83.  
  84. /*this was rejected by my teacher,she said a lot of codes is missing. the problem is, I don't know what i'm going to write coz im new with C. Can you pls. help me with my problem?
  85. thanks a lot!
  86. */
wow! thank you very much!! it is very helpful to me..
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1
Reputation: noelaligoy is an unknown quantity at this point 
Solved Threads: 0
noelaligoy noelaligoy is offline Offline
Newbie Poster

Re: Decimal system to Binary, Octal and Hexadecimal system Conversion..

 
0
  #6
Oct 3rd, 2008
what is the code of this:


----------------------------------------

This program will convert octal to hexa:

Enter a number: ----

What Would you like to do, Press O for octal and H for hexa: -----

The Answer is: -----

Would you like to convert again(Y/N): ----


thanks
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC