(langsam wirds mĂĽhsam)
while((zahl>0)
{
ziffer=zahl%basis;
printf("%d",ziffer);
zahl=zahl/basis;
}
static char digitvalue(unsigned int digit, unsigned int base, int ucase) {
if (digit > base)
return '?';
if (digit <= 9)
return '0' + digit;
return (ucase ? 'A' : 'a') + digit - 10;
}
void conv_to_base(double x, unsigned int base, char *buf, int ucase) {
double exp;
if (x < 0) {
*buf++ = '-';
x *= -1;
}
if (x == 0) {
*buf = '0';
return;
}
exp = base;
while ((exp * base) < x)
exp *= base;
while (exp >= 1 || x != 0) {
*buf++ = digitvalue(x / exp, base, ucase);
x -= ((unsigned int) (x / exp)) * exp;
if (exp == 1 && x != 0)
*buf++ = '.';
exp /= base;
}
*buf = '\0';
}
int main() {
char buf[64];
conv_to_base(-355623.9921875, 16, buf, 0);
printf("%s\n", buf);
return 0;
}
Mitglieder in diesem Forum: 0 Mitglieder und 11 Gäste