how can I display a 64 bit number (2 longs) as decimal
I am working on software to decode a RFID chip that has a 64 bit ID. I know that it will be easy to display the hexadecimal value. However, I need to be able to display it as decimal. I actually only need the least significant 37 bits. How would I go about doing this?
·
·

Comments
var long dividend[noparse][[/noparse] 2 ] byte buffer[noparse][[/noparse] 25 ] pub convert | i ' return the starting address of a string with the decimal value result := @buffer[noparse][[/noparse]24] byte[noparse][[/noparse]result]~ repeat byte[noparse][[/noparse]--result] := divBy10 + "0" while dividend[noparse][[/noparse] 0 ] or dividend[noparse][[/noparse] 1 ] pri divBy10 | i, temp result := 0 repeat i from 1 to 0 temp := (result << 24) | dividend[noparse][[/noparse] i ] result := temp // 10 dividend[noparse][[/noparse] i ] := temp / 10▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
PUB start | i dividend[noparse][[/noparse]1] := $1BF2 dividend[noparse][[/noparse]0] := $1B02CA 'start term text.start(16) text.str(string("12345678901234567890",13,10)) text.str(convert) pub convert | i ' return the starting address of a string with the decimal value result := @buffer[noparse][[/noparse]12] byte[noparse][[/noparse]result]~ repeat byte[noparse][[/noparse]--result] := divBy10 + "0" while dividend[noparse][[/noparse] 0 ] or dividend[noparse][[/noparse] 1 ] byte[noparse][[/noparse]--result] := divBy10 + "0"pri divBy10 | i, temp result := 0 repeat i from 1 to 0 temp := (result << 24) | dividend[noparse][[/noparse] i ] result := temp // 10 dividend[noparse][[/noparse] i ] := temp / 10I ran your program using tv_text instead of vga_text and didn't see any leading spaces. I also eliminated your extra byte[noparse][[/noparse]--result] := divBy10 + "0", since it was giving me a leading zero.
-Phil
text.str(string("12345678901234567890",13))
Thanks! All is well now.
n = binary number to convert to decimal string
dec2add:="1",0 'NOT VALID SPIN set one decimal string to 1
str:="0",0 'NOT VALID SPIN set output decimal string to 0
repeat until n==0
if n&1 = 1
_adddec (str, dec2add) 'NOT VALID SPIN str := str+dec2add
n=n/2 'divide by 2
adddec (dec2add,dec2add) 'NOT VALID SPIN dec2add := dec2add x 2
Adddec would be a simple chalkboard addition of the second string to the first.
I tried to describe it more but I made it sound too complicated.