I found out that I can not use "%llu" or "%lld" in xv6.
All I could use is "%d" for printing integer.
Is there any way I can print long long integer in xv6?
I tried converting long long to string, but things didn't go well.
You can split up the number. With a 32-bit int this should work for values up to 4294967295999999999.
#include <stdio.h>
int main(void) {
unsigned long long n = 1234500000006789;
//unsigned long long n = 4294967295999999999;
unsigned int top = (unsigned int)(n / 1000000000);
unsigned int bot = (unsigned int)(n % 1000000000);
if(top)
printf("%u%09u\n", top, bot);
else
printf("%u\n", bot);
}
Output
1234500000006789
For signed values, detect the sign first, output - and negate.
You can split up the number. With a 32-bit
intthis should work for values up to4294967295999999999.Output
For signed values, detect the sign first, output
-and negate.