Race--Decimal conversion hex--Problem Solving report

Source: Internet
Author: User
Tags uppercase letter

Decimal conversion hex Problem

Main topic:

Converts a decimal integer to 16, in the form of 0x, 10~15 is represented by an uppercase letter, a~f.

Requirements:

Input

One integer per line x,0<= x <= 2^31.

Output

Each row outputs a corresponding eight-bit hexadecimal integer, including the leading 0.

Input Sample:

Input

0

1023

Output

0x00000000
0x000003ff

Topic Analysis:

Output in hexadecimal format converter

Program code:

1#include <cstdio>2#include <iostream>3 using namespacestd;4 5   intMain ()6   {7   intx;8    while(cin>>x)//Enter multiple sets of cases9   {Tenprintf"0x%.8x\n", x);//output in hexadecimal format One   } A     return 0; -}

Experience:
Just see the topic is to think of the topic is very complex, both in 16 in the form of output, but also the output of capital letters, the output of the time includes the leading 0, see the topic is not know how to do, and then carefully think of the original is very simple, as long as with printf ("0x%08X", X); Where 0x itself outputs, 08 means the output is 8 hexadecimal, and X is output in uppercase letters, so that the requirements can be satisfied. In fact, this is a very simple topic, think about it will find only the most basic knowledge of C language.

Match-decimal conversion hex-Problem Solving report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.