I have 2 variables: A as boolean (1 bit, Flowcode 6) and B as byte (8 bits).
I want to put the LSB of B into A. Best best way is A= B & 0x01. But I have lack on memory. Thus my question is if A=B is enough? Or would that give unexpectable results?
Kind regards
Jan Lichtenbelt
Get Boolean from Byte
Moderator: Benj
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Get Boolean from Byte
Hi Jan,
It depends on how good the compiler is and if there are other boolean variables present in the program that it can combine together to make up a byte. The device can only store or process 8-bit values so it is likely that there may be complications in some cases when your not using the and operation. A standard GCC compiler should cope ok but will probably be adding the and operation behind the scenes plus more code to shift the bool val to the correct location in the storage byte.
The best way is probably to do some testing with some corner case situations and see what you get on the hardware. In honesty I hardly even use bool variables because of these complications, they are not worth the hassle and uncertainty. I use bytes and then if I need flags in the byte then I can control them myself without hoping the compiler will provide the additional optimisation.
It depends on how good the compiler is and if there are other boolean variables present in the program that it can combine together to make up a byte. The device can only store or process 8-bit values so it is likely that there may be complications in some cases when your not using the and operation. A standard GCC compiler should cope ok but will probably be adding the and operation behind the scenes plus more code to shift the bool val to the correct location in the storage byte.
The best way is probably to do some testing with some corner case situations and see what you get on the hardware. In honesty I hardly even use bool variables because of these complications, they are not worth the hassle and uncertainty. I use bytes and then if I need flags in the byte then I can control them myself without hoping the compiler will provide the additional optimisation.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel