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

  • Home
  • SEARCH
  • 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 1027551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:15:23+00:00 2026-05-16T12:15:23+00:00

pixel_data is a vector of char . When I do printf( 0x%1x , pixel_data[0]

  • 0

pixel_data is a vector of char.

When I do printf(" 0x%1x ", pixel_data[0] ) I’m expecting to see 0xf5.

But I get 0xfffffff5 as though I was printing out a 4 byte integer instead of 1 byte.

Why is this? I have given printf a char to print out – it’s only 1 byte, so why is printf printing 4?

NB. the printf implementation is wrapped up inside a third party API but just wondering if this is a feature of standard printf?

  • 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-16T12:15:23+00:00Added an answer on May 16, 2026 at 12:15 pm

    You’re probably getting a benign form of undefined behaviour because the %x modifier expects an unsigned int parameter and a char will usually be promoted to an int when passed to a varargs function.

    You should explicitly cast the char to an unsigned int to get predictable results:

    printf(" 0x%1x ", (unsigned)pixel_data[0] );
    

    Note that a field width of one is not very useful. It merely specifies the minimum number of digits to display and at least one digit will be needed in any case.

    If char on your platform is signed then this conversion will convert negative char values to large unsigned int values (e.g. fffffff5). If you want to treat byte values as unsigned values and just zero extend when converting to unsigned int you should use unsigned char for pixel_data, or cast via unsigned char or use a masking operation after promotion.

    e.g.

    printf(" 0x%x ", (unsigned)(unsigned char)pixel_data[0] );
    

    or

    printf(" 0x%x ", (unsigned)pixel_data[0] & 0xffU );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 508k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Nice challenge for a rainy Monday evening (it is here,… May 16, 2026 at 4:21 pm
  • Editorial Team
    Editorial Team added an answer Fixed the problem by stripping out all getPreferredWidth/Height stuff, removed… May 16, 2026 at 4:21 pm
  • Editorial Team
    Editorial Team added an answer Including a template which just handles form displaying. The problem… May 16, 2026 at 4:21 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

One thing that seems particularly easy to do in the Flash IDE but difficult
I can find many examples on how to do this in managed c++ but
I'm using Dipperstein's bitarray.cpp class to work on bi-level (black and white) images where
Possible Duplicate: Growable data structure in MATLAB So in my current MATLAB script, I
I wish to draw an image based on computed pixel values, as a means
I've been working on a visualization project for 2-dimensional continuous data. It's the kind
I wonder if and how writing almighty classes in c++ actually impacts performance. If
I am currently working on an image processing demonstration in java (Applet). I am
i am trying to extract outline path from given bitmap, i create a fast
Does anyone have a suggested methodology for visualising the data in a star catalogue

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.