I was writing some function to convert base of an integer, I am using Ideone this code on ideone
While it works fine on Ideone , on C::B it gives the output 484
. I am using -std=c++11
,even without it (or using -std=c++0x
) , the output is still incorrect.
so is this something wrong with code or compiler ?
I am using mingw on windows ( gcc 4.7.1 )
#include<iostream>
#include<cmath>
#define bigint long long unsigned int
bigint base(int numberOldBase, int newBase)
{
bigint numberNewBase = 0;
int digitCounter = 0, remainder[100];
while (numberOldBase)
{
remainder[digitCounter] = numberOldBase % newBase;
numberOldBase /= newBase;
digitCounter++;
}
for (int currentDigit = 0; currentDigit < digitCounter; currentDigit++)
{
numberNewBase += ((remainder[currentDigit]) * pow(10, currentDigit));
}
return numberNewBase;
}
int main()
{
std::cout << base(1025, 15);
return 0;
}