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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:16:25+00:00 2026-05-20T08:16:25+00:00

I know how to cause it to be in hex: unsigned char myNum =

  • 0

I know how to cause it to be in hex:

unsigned char myNum = 0xA7;
clog << "Output: " std::hex << int(myNum) << endl;
// Gives:
//   Output: A7

Now I want it to always print a leading zero if myNum only requires one digit:

unsigned char myNum = 0x8;
// Pretend std::hex takes an argument to specify number of digits.
clog << "Output: " << std::hex(2) << int(myNum) << endl;
// Desired:
//   Output: 08

So how can I actually do this?

  • 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-20T08:16:26+00:00Added an answer on May 20, 2026 at 8:16 am

    It’s not as clean as I’d like, but you can change the “fill” character to a ‘0’ to do the job:

    your_stream << std::setw(2) << std::hex << std::setfill('0') << x;
    

    Note, however, that the character you set for the fill is “sticky”, so it’ll stay ‘0’ after doing this until you restore it to a space with something like your_stream << std::setfill(' ');.

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

Sidebar

Related Questions

I know this question is probably stoopid. But I just don't want to cause
I'm facing a problem where I know the root cause but don't see a
I'm looking without success (maybe cause i don't know how to call this slider)
I don't know the cause of these errors I am receiving from Visual Studio
How can I get decimal from string hexdecimal: I have unsigned char* hexBuffer =
Does anyone know why native2ascii generates lower-case hex codes, while Properties.store() produces upper-case hex?
Starting from a hex source, i want to convert it to a-zA-Z0-9 . base_convert()
I get the following security exception in GAE, anyone know the cause? Google searches
Probably have wrong title,but I don't know how to describe it. int x=0x4a; h=!(0x80000000000&(0x39+(~x+1)));
As we all know in case of multiple threads each thread maintains it's separate

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.