Moving/Seperating numbers
JBWolf
Posts: 405
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
AllVars := VarA | VarB<<4 | VarC<<8
The reverse operation is:
VarA := AllVars & %1111
VarB := AllVars>>4 & %1111
VarC := AllVars>>8 & %1111