c++ an instance of a hexadecimal number converted to any 2 hexadecimal number

  • 2020-05-24 05:52:55
  • OfStack

Without further ado, go straight to the code


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main()
{
  //10 Convert a base to a number of bases >2,<16 =
  int num;
  int n;//2-16 between 
  int a;
  int i=0;
  cin>>num>>n;
  int s[100];
  if(n>=2&&n<<16)
  {
    while(num!=0)
    {
      a=num%n;
      num=num/n;
      i++;
      s[i]=a;

    }
    for(int j=i;j>=1;j--)
    {
      if(s[j]>=10)
      {
        cout<<s[j]+55;
      }
      else{
      cout<<s[j];
      }
    }
  }
  else{

    cout<<"error"<<endl;
  }
}

Related articles: