Page 1 of 1

ESP32 and BIT order LSB to MSB or vice versa

Posted: Mon Jan 25, 2021 12:43 pm
by dvcam99
Hello Matrix Team,

in my good old FC4 days the following function/calculation I got from JonnyW was working perfect!! :D

byte = (byte >> 7) & 1 | (byte >> 5) & 2 | (byte >> 3) & 4 | (byte >> 1) & 8 | (byte << 1) & 0x10 | (byte << 3) & 0x20 | (byte << 5) & 0x40| (byte << 7) & 0x80


The purpose was to change the bit order inside a byte from LSB to MSB or vice versa.

Unfortunately the ESP32 compiler is not accepting this and the build failed.

Any ideas for a solution??

BR

Dirk

Re: ESP32 and BIT order LSB to MSB or vice versa

Posted: Mon Jan 25, 2021 12:51 pm
by LeighM
Did you forget the semicolon at the end of the statement? - if C
Or are you using this in Flowcode calculation?

Re: ESP32 and BIT order LSB to MSB or vice versa

Posted: Mon Jan 25, 2021 1:02 pm
by dvcam99
....mh i belive not because that string was put in a FC calculation box!!

I`ll check with a C-Box too and semikolon!!

BR

Dirk

Re: ESP32 and BIT order LSB to MSB or vice versa

Posted: Mon Jan 25, 2021 1:23 pm
by dvcam99
OK I put the follwing sentence in a C-Box, unfortunatley the ESP32 compiler still faild to build.

FCV_BYTE = (FCV_BYTE >> 7) & 1 | (FCV_BYTE >> 5) & 2 | (FCV_BYTE >> 3) & 4 | (FCV_BYTE >> 1) & 8 | (FCV_BYTE << 1) & 0x10 | (FCV_BYTE << 3) & 0x20 | (FCV_BYTE << 5) & 0x40| (FCV_BYTE << 7) & 0x80;

Re: ESP32 and BIT order LSB to MSB or vice versa

Posted: Mon Jan 25, 2021 2:05 pm
by LeighM
Try this instead...

Code: Select all

byte = ((byte >> 7) & 1) | ((byte >> 5) & 2) | ((byte >> 3) & 4) | ((byte >> 1) & 8) | ((byte << 1) & 0x10) | ((byte << 3) & 0x20) | ((byte << 5) & 0x40) | ((byte << 7) & 0x80)

Re: ESP32 and BIT order LSB to MSB or vice versa

Posted: Mon Jan 25, 2021 2:18 pm
by dvcam99
TOP our are great!! Works!! :D :D :D

Many thanks