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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:30:16+00:00 2026-06-15T20:30:16+00:00

I am required to write a function called bitstring, which takes a unsigned char

  • 0

I am required to write a function called bitstring, which takes a unsigned char that was created in this function:

size_t bs2n(string s)
{
  assert (s.size() > 0);
  if (s.size() == 1) 
    return s[0]-'0';
  else {
    string smaller = s.substr(0,s.size()-1); 
    return 2 * bs2n(smaller) + s[s.size()-1] - '0';
  }
}

This function takes 8 bits and returns a unsigned char between 0-255

I need to be able to convert it back, but I encountered a problem when writing down the function parameters and first line from class.

What I have is:

string unsignedchar bitstring(unsigned char)

I think for one that it should be:

string unsigned char bitstring(unsigned char val)

which would make a heck of a lot more sense, but still doesn’t make sense why I need the first unsigned char…

How should I write the first line of the function?

  • 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-15T20:30:17+00:00Added an answer on June 15, 2026 at 8:30 pm

    The parameters aren’t your problem, it would be your function declaration. You declare two return types to the function

    string unsigned char bitstring(unsigned char val)
    

    The function returns a string…wait no… an unsigned char… you need to define just one return type, e.g. leave out string. what you want to accomplish would be an array of unsigned chars, thus requiring the char to return a pointer to chars.

    void bitstring(unsigned char val, unsigned char* array) //write to array
    
    • Note though that returning arrays is a bad practice and generally fails, if you allocate the array in the function and return a reference to it the reference will fail because the array will deconstruct at the end of a function. A better solution would be to pass an array that you want to read into as a parameter to the function, then write to THAT array.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

write a script that takes two optional boolean arguments,--verbose‚ and ‚--live, and two required
So basically I want to write a function that can be written like this:
I am required to write a script that would download a file (based on
I'm required to write a JCE provider. I have learned that I need to
I have a class called User with static function loginRequired(), which returns false if
I'm trying to write a unit test against a single module function. This module
I want to write a function which employs openMP parallelism but should work whether
I am trying to write a simple dialog that is called by the flash
I'm trying to write a string to a socket (socket is called response). Here
I have a need for a high-performance string hashing function in python that produces

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.