Bitwise Operations
Hi,
I have been using BasicMicro Stamp and Atom controller(s) for many years and have just switched to the EM1202 for the first time in a project. I have found it a great product, but there appears to be a huge omission in terms of programming - individual bit manipulation within byte/word/long variables. Unless I am missing something, there appears to be no easy way of doing this?
In a previous Atom application I used a 32-bit variable as a "register" to record 32 pass/fail criteria. There is facility in Atom Basic to simply turn individual bits in the variable on or off or use them in operations. You can also separate out any byte of a 16 or 32-bit variable and carry out many other bitwise operations. I can find no way to do these simply in Tibbo Basic.
I have a work-around by converting the variable to a 32-character binary string representation, manipulating the characters in the string, then converting back to a 32-bit variable. This is VERY slow at processing.
Am I missing something? If not, PLEASE can we have full bitwise operations in the next release? The Atom was superb at this, so please consult their manual for ideas! There is a whole range of operations I simply can't find a way of doing on the EM1202.
Hugh
I have been using BasicMicro Stamp and Atom controller(s) for many years and have just switched to the EM1202 for the first time in a project. I have found it a great product, but there appears to be a huge omission in terms of programming - individual bit manipulation within byte/word/long variables. Unless I am missing something, there appears to be no easy way of doing this?
In a previous Atom application I used a 32-bit variable as a "register" to record 32 pass/fail criteria. There is facility in Atom Basic to simply turn individual bits in the variable on or off or use them in operations. You can also separate out any byte of a 16 or 32-bit variable and carry out many other bitwise operations. I can find no way to do these simply in Tibbo Basic.
I have a work-around by converting the variable to a 32-character binary string representation, manipulating the characters in the string, then converting back to a 32-bit variable. This is VERY slow at processing.
Am I missing something? If not, PLEASE can we have full bitwise operations in the next release? The Atom was superb at this, so please consult their manual for ideas! There is a whole range of operations I simply can't find a way of doing on the EM1202.
Hugh
1 person has this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
-
Inappropriate?Hey Hugh,
Was wondering what bit-wise operators you feel is missing that you found useful? We do have the AND, OR, XOR, and NOT operators.
-
Inappropriate?Hi T-bone,
Here are some extracts from Atom Basic syntax that I find invaluable:
VARIABLE MODIFIERS (syntax variable.modifier):
lowbit, highbit, bitn, lownib, highnib, nibn, lowbyte, highbyte, byten,
lowword, highword, wordn
So for example, to set the 20th bit of 32-bit variable "stateregister" high:
stateregister.bit20=%1
or to convert the 32-bit variable to a 4-digit hex representation:
errorcode(0)=HEX stateregister.nib3
errorcode(0)=HEX stateregister.nib2
errorcode(0)=HEX stateregister.nib1
errorcode(0)=HEX stateregister.nib0
Comparison operators (<, >, =, <=, >=, <>) can be used at any of the above levels (bit, nibble, byte, word, long).
BITWISE OPERATORS:
& AND expr1 & expr2
| OR expr1 | expr2
^ XOR expr1 ^ expr2
>> Shift Right expr1>>expr2
<< Shift Left expr1 << expr2
~ Invert Bits ~ expr1
! Invert Bits ! expr1
BIT LEVEL FUNCTIONS:
SHIFTIN read data one bit at a time to synchronous serial device.
SHIFTOUT write data one bit at a time to a synchronous serial device
So for example to send a 32-bit variable "stateregister" to a synchronous serial device starting with MSB first:
SHIFTOUT DEVICE_DATA,DEVICE_SCLK,MSBPOST,[stateregister\32]
RELATED FUNCTIONS:
BIN2BCD, BCDTOBIN convert between binary and packed BCD
DIG isolate a single digit of a decimal number
There just seems to be no simple way to work with data at the bit, nibble, word, long levels (intermixed) which for low-level engineering applications on the back-end of the excellent high-level comm's capabilities I find very limiting. I am actually using a EM1202 and Atom Pro 28M together on one board at the moment with serial link between them! I would eventually like to use just the EM1202.
Any thoughts? Thanks for listening :)
I’m thanks for listening
-
Inappropriate?I'm experiencing some of the limitations myself as i'm coding a base64 encode/decode routine.
But the workaround is to basicly convert the binary data to string and work on it, or to make logic operations.
Some examples,
Setting the 20th bit of the y 32bit long variable
y=y OR &h080000
clearing the 20th bit,
y=y AND &hF7FFFF
Inverting the 20th bit,
y=y XOR &h080000
Some sort of shift left,
x=Lbin(y) 'convert y to string
x=right(x,len(x)-2) 'remove the annoying &b from the string
z=left(x,1) 'get the first caracter 0 or 1
x=right(x,len(x)-1) 'Shift left
Use a similar for the shift right.
It's not as quick or straight forward as i used to work in MicroChip Pic, but it does the job if you don't have time sensitive aplications.
For those i use a combination of the EM1202 with a pic controler, for example with one-wire ibutton protocols.
Loading Profile...




