I am writing a program in C and I have several printf statements for debugging. Is there a way to change the precision for a HEX output on printf? Example. I have 0xFFF but I want it to print out 0x0FFF.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Say
printf("%04X", x);.The
0means “pad with zeros”, the4means “at least four characters wide”.For integers, one doesn’t use the term “precision” (because integers are precise), but rather “field width” or something like that. Precision is the number of digits in scientific notation when printing floats.