Showing results for 
Search instead for 
Did you mean: 

Continuously writing/reading 24 bytes of data to serial device

Go to solution

@GerdW wrote:

Hi grumpy,


@grumpy_numpy wrote:

In any case, your suggestion reduced the volume significantly.

Why don't you use our advice (BooleanArrayToNumber)? Why do you need to stick with that huge amount of multiply/add functions to create a simple U8 value from 8 boolean values?

From a pure performance point of view his code may actually be just as performant or better than a BooleanArrayToNumber function. Arrays involve the memory manager, creating and disposing of arrays are costly operations. Of course unless you call this code in a tight loop zillion of times, you would be hard pressured to measure much of a difference between the different variants.


But I would definitely replace the multiplication with a Logical Shift. A multiplication is more costly than a logical shift when you deal with Powers of 2. And it shows more clearly the boolean character of the data than a multiplication with some power of 2 constant.

Rolf Kalbermatter
Averna BV
Message 11 of 11