Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7712839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:43:40+00:00 2026-06-01T01:43:40+00:00

I am trying to learn how to convert ints into binary. it runs but

  • 0

I am trying to learn how to convert ints into binary. it runs but this is the output: Enter a number: 33
New value: 16
Remainder: 1
Current VAlue: -17
Counter: 1

I appreciate any help. Thank you. Ok I am sorry my bad. The output should be: 00100001

#include <stdio.h>

int main()
{
  int nv, r, num;

  printf("Enter a number: ");
  scanf("%d",&num);

   int counter=0;
   while(num>=0)
   {
      nv=num/2;
      r=num%2;
      num=-(nv+r);
      counter++;

    printf("New Value: %d\n",nv);
    printf("Remainder: %d\n",r);
      printf("Current Value: %d",num);
   }
    printf("Counter: %d\n",counter);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:43:42+00:00Added an answer on June 1, 2026 at 1:43 am
    num=-(nv+r);
    

    Is obviously negative, since both nv and r are positives.

    I suspect you actually wanted

    num = nv
    

    or:

    num -= (nv + r)
    

    Also note that your stop condition is num >= 0 – if you do the first change, you will get an infinite loop, since when you reach num ==0, you will divide by 2, and get nv == num /2 == 0 / 2 == 0 and assign nv back to num

    (*)Note that also the second change will proide infinite loop: 0 % 2 == 0 and 0 / 2 == 0, so num -= (nv + r) == 0 - (0 + 0) == 0

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to learn and practice arrays but I have a problem with this small
Trying to learn a bit about PDO and is going through this tutorial .
I'm trying to learn about this feature of javascript I keep seeing in code,
Sorry about this silly question. I'm trying to learn objc and I'm unable to
Trying to learn F# but got confused when trying to distinguish between fold and
I'm trying to learn NASM assembly, but I seem to be struggling with what
I have done a lot with Java but I am currently trying to learn
I am trying to learn how to convert a string to an integer. I
I haven't used Ruby much but I am trying to learn. I found a
I've always worked with Windows Forms, but now I'm trying to learn WPF due

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.