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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:38:47+00:00 2026-06-04T18:38:47+00:00

I’m a Java developer who tries to code C++ in the limited Arduino environment.

  • 0

I’m a Java developer who tries to code C++ in the limited Arduino environment. Exceptions and dynamic objects are not available or have to be avoid because of memory restrictions.

My task, create a method which parses a character buffer (hex nibble) and returns a boolean value to indicate the success as well as the actual result. My attempt so far (unrelated stuff avoided):

class Parser {
   unsigned char buffer[SIZE];
   unsigned char index;

   void parse();
   bool parseHexNibble(unsigned char &result);
};

void Parser::parse() {
  unsigned char result = 0;
  if (!parseHexNibble(result)) {
    return;
  }

  // do some work with result
}

bool Parser::parseHexNibble(unsigned char &result) {
  unsigned char chr = buffer[index];
  if (chr >= '0' && chr <= '9') {
    result = chr - '0';
  }
  else if (chr >= 'A' && chr <= 'F') {
    result = chr - 'A' + 10;
  }
  else {
    return false;
  }

  index++;
  return true;
}

Will this work? I’m unsure when to use * and when to use &. Is there a better solution?

  • 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-04T18:38:49+00:00Added an answer on June 4, 2026 at 6:38 pm

    There are a few ways:

    The way you did it is one of them, although I recommend using a pointer rather than a reference (* instead of &) because with references, the function call looks like you are passing a value (p.parseHexNibble(c)) while the pointer version is more clear that you may want something stored in it (p.parseHexNibble(&c)).

    Another option, (this one is my personal favorite) is the same thing that getc does: Return an int that either contains a char value (0 <= i < 256) or is -1 to signal an error. In the case of no error, the int can safely be typecast and/or stored to a char. (This assumes that it is a char in fact that you want to return.)

    The third way is to return a structure containing a boolean and a character (either by making your own or by using std::pair or the like).

    On an unrelated note, you should be using char rather than unsigned char to store actual character values. unsigned char should only be used for arbitrary raw data.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.