Get Boolean from Byte

For Formula Flowcode Micromouse users to discuss projects, flowcharts, and any other issues related to the Formula Flowcode Micromouse.

Moderator: Benj

Post Reply
User avatar
Jan Lichtenbelt
Posts: 796
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Contact:

Get Boolean from Byte

Post by Jan Lichtenbelt »

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

User avatar
Benj
Matrix Staff
Posts: 15147
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Get Boolean from Byte

Post by Benj »

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.

Post Reply