Table of Contents

URI Online Judge | 1957

Converting to Hexadecimal

By M.C. Pinto, UNILA BR  Brazil
Timelimit: 1
Data stored in computers are in binary. An economic way of visualizing these numbers is the usage of base 16 (hexadecimal). Your task is to write a program that, given a natural number at base 10, shows its representation in hexadecimal.

Input

The input is a positive integer number V at base 10 (1 ≤ V ≤ 2 x 109).

Output

The output is the same number V at base 16 in a single line (don’t forget the end-of-line character). Use uppercase letters, as shown in the examples.
 
Input Samples Output Samples
10 A
15 F
16 10
 

Solution


#include 
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i=0;
    cin>>n;
    int arr[100000];
    while(n)
    {
       arr[i]=n%16;
       n/=16;
       i++;
    }
    while(i--)
    {
        if(arr[i]==10)
        {
            cout<<'A';
        }
        else if(arr[i]==11)
        {
            cout<<'B';
        } else if(arr[i]==12)
        {
            cout<<'C';
        } else if(arr[i]==13)
        {
            cout<<'D';
        } else if(arr[i]==14)
        {
            cout<<'E';
        } else if(arr[i]==15)
        {
            cout<<'F';
        }
        else cout<<arr[i];
}cout<<endl; return 0; }  
Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on pinterest
Pinterest
Share on whatsapp
WhatsApp
Share on email
Email
Md. Nurnobi Hosen
Md. Nurnobi Hosen

Student of Computer Science and Engineering at Daffodil International University,Main Campus ,Dhanmondi.
Web and App Developer also expart of wordpress customization

All Blog Posts »
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x