nelsyeung / base-conversion

Base conversion from one base representation to another, ranging from 2 to 36

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Base Conversion

C++ function to convert numbers from one base representation to another, ranging from 2 to 36. Requires C++11

Usage

n::convert_base(string input, int baseFrom, int baseTo);
n::convert_base("100", 2, 10);
returns "4"

n::convert_base(int input, int baseFrom, int baseTo);
n::convert_base(100, 2, 10);
returns "4"

Full example

#include <iostream>
#include "base_conversion.hpp"

int main()
{
    std::cout << n::convert_base("100", 2, 10) << std::endl;

    return 0;
}

About

Base conversion from one base representation to another, ranging from 2 to 36

License:MIT License


Languages

Language:C++ 100.0%