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 6723769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:36:31+00:00 2026-05-26T09:36:31+00:00

I have a homework. The question is: Write a function that takes as parameter

  • 0

I have a homework. The question is:

Write a function that takes as parameter a single integer, int input, and returns an unsigned character
such that:
a- if input is negative or larger than 11,111,111 or contains a digit that is not 0 or 1; then the function will
print an error message (such as “invalid input”) and return 0,
b- otherwise; the function will assume that the base-10 value of input represents a bit sequence and return the magnitude-only bit model correspondent of this sequence.

For Example: If input is 1011, return value is 11 and If input is 1110, return value is 14

This is my work for a, and I am stuck on b. How can I get bit sequence for given integer input?

int main()
{
    int input = 0;

printf("Please type an integer number less than 11,111,111.\n");
scanf("%d",&input);

if(input < 0 || input > 11111111)
{
    printf("Invalid Input\n");
    system("PAUSE");
    return 0;
}


for (int i = 0; i < 8; i++)
{
    int writtenInput = input;
    int single_digit = writtenInput%10;

    if(single_digit == 0 || single_digit == 1)
    {
        writtenInput /= 10;
    }
    else
    {
        printf("Your digit contains a number that does not 0 or 1. it is invalid input\n");
    system("PAUSE");
    return 0;
    }
}

printf("Written integer is %d\n",input);

system("PAUSE");
return 0;
}
  • 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-05-26T09:36:31+00:00Added an answer on May 26, 2026 at 9:36 am

    The bit that you are missing is the base conversion. To interpret a number in base B, what you need to do is multiply digit N times B^N (assuming that you start counting digits from the least significative). For example, in base 16, A108 = (10)*16^3 + 1*16^2 + 0*16^1 + 8*16^0. Where in your base is 2 (binary).

    Alternatively, you can avoid the exponentiation if you rewrite the expression as:

    hex A008 = ((((10*16) + 1)*16 +0)*16 + 8
    

    Which would be simpler if your input was stated in terms of an array of possibly unknown length as it is easily convertible into a loop of only additions and multiplications.

    In the particular case of binary, you can use another direct solution, for each digit that is non-zero, set the corresponding bit in an integer type large enough (in your case, unsigned char suffices), and the value of the variable at the end of the loop will be the result of the conversion.

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

Sidebar

Related Questions

I have a compiler homework question that wants me to draw a DFA for
Here is my homework question: Write a program that asks for a film name
I have a question about my homework problem. Here is the problem: Write a
I hate that I have to ask a homework question on here, but I
Okay, so I have another question on a prolog homework problem I am struggling
I have a homework assignment where I need to take input from a file
I have a homework that I just can't figure out how to do. I'm
I have a homework question regarding operator precedence in Fortran. In order to understand
I have been pondering about my homework question for a while. I welcome (and
This is a homework question,I'm trying to do a Depth-first search function in Scheme,Here's

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.