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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:09:17+00:00 2026-05-19T14:09:17+00:00

I have looked at this answer and can’t get it to work for my

  • 0

I have looked at this answer and can’t get it to work for my situation. Please don’t mark this as a duplicate as I can’t get any of those answers to satisfy my situation.

I am mallocing some memory and copying data into that memory. I want to be able to print out the values of each of the bytes in hex in the format 0xFF where a byte equals 255.

I have cast my void* pointer to the memory as char* and am iterating the block of memory, but when I try and print out the values I get very wide output instead of two digits I get the full width of the unsigned int.

std::ostream& operator << (std::ostream &os, const Binary &obj)
{
    char* aschar = (char*) obj.buffer;
    for (long i = 0; i < obj.size; i++) 
    {
        if (isprint(aschar[i])) 
        {
            os << aschar[i];
        }
        else 
        {
            os << std::hex << std::setw(2) << std::setfill('0') << static_cast<unsigned int> (aschar[i]);
        }
    }
    return os;
}

I am memseting all the bytes to 128 in my test case. And all what I get back is ffffff80 when I am expecting 80. I am sure it has something to do with the casting and what not but I can’t figure out how to express this the way I want it to.

I have also tried using sprintf and I can’t get it to behave the way I want it to either. I am using Xcode 3.2.5 64 bit with GCC 4.2.1 if it matters.

  • 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-19T14:09:18+00:00Added an answer on May 19, 2026 at 2:09 pm

    Use unsigned char *aschar instead of (signed) char *aschar.

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

Sidebar

Related Questions

I have looked all over but can't find an answer to this... Quite simply
I have looked for an answer for this nearly every where that I can
I have looked everywhere on the internet and can not find this answer. Do
Okay, I have looked hard for this answer, but all the websites, even the
Have looked quite hard for this answer but having no luck. I have 3
I have looked everywhere for this and just cannot find the answer. I have
I've looked and looked and I'm not seeing the answer to this. I have
Ok.. I have looked through this site and just can't seem to find the
I have looked everywhere for the answer to this question, but cannot find anything
I have looked around and can't find a good answer to what I'm trying

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.