I have coded following algorithm to convert a decimal value into Binary/Hexadecimal etc..
string toFormatFromDecimal(long long t, Format format) { int digitCount = ceil(log(t) / log((int) format)); string hex = ""; for (int i = 0; i < digitCount; i++) { long double cur = (long double)t / (long double)(format); long long ganzzahl = (long long) cur; long double kommazahl = cur - ganzzahl; hex += digits[(long long) (kommazahl * format)]; t = ganzzahl; } return string(hex.rbegin(), hex.rend());}
I use GCC in linux and Visual Studio c++ compiler on WindowsIt seems that i got different values at the "integer" Division here:
long long ganzzahl = (long long) cur;
Any Idea how this could happen? are there different precissions on Linux and Windows?
ThanksFlorian
--Solution--
string toFormatFromDecimal(long long t, Format format) { int digitCount = ceil(log(t) / log((int) format)); string hex = ""; for (int i = 0; i < digitCount; i++) { hex += digits[(int) (t%format)]; t = t/format; } return string(hex.rbegin(), hex.rend());}