decimal code decoder code example

Example: decimal to english

#include<iostream>
#include<string>

inline std::string binary_conv(int,int,std::string);

int main()
{
    long int number;
    int base {27};
    std::cout<<"\nPlease enter a non-negative integer:\t";
    std::cin>>number;
    while(number<=0)
    {
        std::cerr<<"\nWRONG!!!, Enter a number higher than zero\n";
        std::cout<<"\nPlease enter a number\t";
        std::cin>>number;
    }
    std::string binary_number;
    binary_number = binary_conv(number,base,binary_number);
    
    
    std::cout<<binary_number<<std::endl;
   
    return 0 ;
}

std::string binary_conv(int number, int base,std::string binary)
{   
    std::string zero_one = " abcdefghijklmnopqrstuvwxyz";
    if(number==0)
        return binary;
    binary = zero_one[number%base]+binary;
    number/=base;
    return binary_conv(number,base,binary);
}

Tags:

Cpp Example