convert decimal to binary

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lathasree
    New Member
    • Aug 2007
    • 1

    convert decimal to binary

    Hi, this is sreelatha give a c progrm to convert decimal to binary....



    thank u....
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by lathasree
    Hi, this is sreelatha give a c progrm to convert decimal to binary....



    thank u....
    We don't handout boiler plate code for you. You have to do your own homework
    but when you're stuck we're very willing to help you. Please show us what
    you've done sofar.

    kind regards,

    Jos

    Comment

    • ilikepython
      Recognized Expert Contributor
      • Feb 2007
      • 844

      #3
      Originally posted by lathasree
      Hi, this is sreelatha give a c progrm to convert decimal to binary....



      thank u....
      This question has been asked multiple times before on these forums and you can easily find it on the internet.

      Comment

      • Girish Kanakagiri
        New Member
        • May 2007
        • 93

        #4
        Originally posted by lathasree
        Hi, this is sreelatha give a c progrm to convert decimal to binary....



        thank u....
        Hint

        make use of mod

        if(n%2 == 0)
        {
        ----
        ----
        }
        else
        {
        ----
        ----
        }

        Regards,
        Girish.

        Comment

        • suresh gani
          New Member
          • Jul 2007
          • 6

          #5
          take recursive function

          fun(int n) {
          static int rem;
          if(n <= 0)
          return ;
          rem = n % 2;
          fun(n/2);
          printf("%d", r);
          }

          Comment

          • leoafro
            New Member
            • Aug 2007
            • 3

            #6
            Originally posted by lathasree
            Hi, this is sreelatha give a c progrm to convert decimal to binary....



            thank u....
            Here is the logic of decimal to binary convertion;
            //before looping, after entering the decimal number
            x=0;
            quotient=DecNum/2;
            remainder[x]=Decnum%2; // This is the initial binary number

            //Inside loop
            x++;
            quotient=quotie nt/2;
            remainder[x]=quotient%2;
            // The loop will end if the value of the quotient will become <=1,
            after the loop ends, you will have to reverse the order of remainder[x]
            and display it.

            Comment

            Working...