Display unsigned cnt in spin
dbpage
Posts: 217
Do you have an elegant spin method to convert cnt to display unsigned 10 ASCII characters in the range of 0 to 4,294,967,295 without PASM support? It seems easy for someone smarter than me.
Comments
I think you need to test to see if the number if negative and if it's negative split the number into to parts.
I can't think of an easy way to split the number to allow you output the 10 characters but I'm sure this is possible.
True, but it is simple to modify the code to print as an unsigned binary number.
Is it? I've modified dec methods a bunch of times but I can't think of a simple way to output an unsigned 32-bit number.
Spin treats all longs as signed numbers.
Andy
Edit: There seems to be a Problem with $8000_0000 and $8000_0001 for the lowest digit.
I think your method always displays a leading zero.
-Phil
The first test for "tmp => 0" ensures that any single digit positive numbers will be printed normally. The rest of the code only deals with unsigned numbers that are much greater than 10 (greater than 2 billion, in fact) so "tmp" will always be non-zero after the divide by 10.
Eric
-Phil
Good work guys. Thanks.
Andy
+1 from me.
I appreciate seeing these solutions.
Nice. Elegant.
By controlling the operator precedence levels, following give identical results:
Yet, even though the above snippet results differ, the following give identical results:
Interesting.