Moving/Seperating numbers
I believe there are some unique ways using SPIN to move bytes and numbers around and was hoping somone could provide some help.
I am compiling multiple variables into one numeric value by multiplying by 10 and adding the next variable.
i.e... AllVars := ((((VarA * 10) + VarB) * 10) + VarC)
None of these individual variables exceed a value of 9 so they can be compiled.
So now I'm trying to find the best way to return it back to multiple variables.
I can only think of a complicated way to do this and the numbers do have remainders which I expect to be lost since the variables are not declared as float.
i.e:
VarA := (AllVars / 100)
VarB := ((AllVars / 10) - (VarA * 10))
VarC := ((AllVars - (VarA * 100)) - (VarB * 10))
I was wondering if there is SPIN code to simplify this task.
Thanks
I am compiling multiple variables into one numeric value by multiplying by 10 and adding the next variable.
i.e... AllVars := ((((VarA * 10) + VarB) * 10) + VarC)
None of these individual variables exceed a value of 9 so they can be compiled.
So now I'm trying to find the best way to return it back to multiple variables.
I can only think of a complicated way to do this and the numbers do have remainders which I expect to be lost since the variables are not declared as float.
i.e:
VarA := (AllVars / 100)
VarB := ((AllVars / 10) - (VarA * 10))
VarC := ((AllVars - (VarA * 100)) - (VarB * 10))
I was wondering if there is SPIN code to simplify this task.
Thanks

Comments
CON _clkmode = XTAL1|PLL16X _xinfreq = 5_000_000 OBJ serial: "FullDuplexSerial" VAR byte digits[16] PUB null | n serial.start(31, 30, %0000, 115200) waitcnt(clkfreq*3 + cnt) serial.tx(0) n := split(123456789) repeat n serial.dec(digits[--n]) serial.tx(13) PRI split(value) : n ' n starts as 0 repeat digits[n++] := ||(value // 10) value /= 10 while value ' fill level is returned DATAllVars := VarA | VarB<<4 | VarC<<8
The reverse operation is:
VarA := AllVars & %1111
VarB := AllVars>>4 & %1111
VarC := AllVars>>8 & %1111