convert stamp var to spin
Dwayne Dibbley
Posts: 63
i have the following varibles from a basic stamp that i would like to use in spin:
in the basic stamp code i need to use the following in spin
it is reading a byte and i need to know BIT0 of that byte?
Thanks
dataWord VAR Word ' data word dataHigh VAR dataWord.HIGHBYTE ' high byte of dataWord dataLow VAR dataword.LOWBYTE ' low byte of dataLow dataByte VAR dataLow ' (alternate name) opcode VAR dataHigh ' opcode (same as dataHigh) format VAR dataLow ' format (same as dataLow) status VAR dataLow ' status (same as dataLow) status_Zero VAR status.BIT0 ' Zero status bit (0-not zero, 1-zero) status_Sign VAR status.BIT1 ' Sign status bit (0-positive, 1-negative) status_NaN VAR status.BIT2 ' Not a Number status bit (0-valid number, 1-NaN) status_Inf VAR status.BIT3 ' Infinity status bit (0-not infinite, 1-infinite)
in the basic stamp code i need to use the following in spin
IF status_Zero THEN dbg.str(string("OK")
it is reading a byte and i need to know BIT0 of that byte?
Thanks
Comments
A simple method to find the value of a bit is to execute a logical AND. %0001 AND %1011 = %0001
Values in Spin are signed so this method protects you from an out-of-range bit position. For your status_Zero you would do this:
...just before you use status_Zero. You need to call the method any time there is possibility that the status variable has changed.
Or, as Spin is much more advanced than PBASIC, you could use the method call in place of a variable: