I was looking at this code from this link:
http://www.gamedev.n...o-ascii-in-asm/
How can I make it support unsigned integer.
I want to convert 3210987654 to its radix, but all i get is a negative number that doesn't correspond to it.
For base 16, for that number I'm suppose to get BF63C886. but in qtspim, I get, -409c377a
much help is very appreciated
3 replies to this topic
Ad:
#2 Members - Reputation: 5796
Posted 05 November 2012 - 08:41 PM
I don't know MIPS assembly, but here's a straight-forward implementation in C++, which you can easily map to assembly:
#include <iostream>
#include <algorithm>
void uitoa(char *s, unsigned x, unsigned radix) {
int i=0;
do {
s[i] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[x%radix];
++i;
x /= radix;
} while (x);
std::reverse(s, s+i);
s[i] = '\0';
}
int main() {
char s[20];
uitoa(s, 3210987654u, 16);
std::cout << s << '\n';
}






