Help! Decimal to binary conversion

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

Join Date: Apr 2006
Posts: 5
Reputation: john_hasan is an unknown quantity at this point 
Solved Threads: 0
john_hasan john_hasan is offline Offline
Newbie Poster

Help! Decimal to binary conversion

 
0
  #1
Apr 22nd, 2006
This program converts a decimal input into a hexadecimal and octal value.But I also want to convert it top binary as well.So kindly guide me.
thanx
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a;
  7. printf("Enter a number");
  8. scanf("%d",&a);
  9. printf("Decimal=%d",a);
  10. printf("\nOctal=%o",a);
  11. printf("\nHexadecimal=%x",a);
  12.  
  13. getch();
  14. }
Last edited by Dave Sinkula; Apr 23rd, 2006 at 5:35 pm.
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: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Help! Decimal to binary conversion

 
0
  #2
Apr 22nd, 2006
I think the whole point of this exercise is for you to write a function along the lines of
  1. void convertToBase( int number, int base, char *result );

Assuming you know how to do this for base 10, through application of the / and % operators, the rest should follow naturally.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC