BIT order LSB to MSB and vice versa

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Dirk Bubley
Posts: 99
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Has thanked: 14 times
Been thanked: 12 times

BIT order LSB to MSB and vice versa

Post by Dirk Bubley »

Hello together,

i try to find my way with BIT manipulation inside a byte.

One problem i can`t solve is changing the bit order inside a byte.

Example i would like to change the order from LSB------MSB to MSB------LSB or vice versa.

Any help would be aprechiated.

BR

Dirk

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: BIT order LSB to MSB and vice versa

Post by medelec35 »

Hi Dirk,
Not sure if this is a helpful for you or not,
but here are could be couple of solutions?

1st Is from a V5 flowchart.
Since you have not got V5 here is a screen shot:
Binary swap.png
(15.82 KiB) Downloaded 1755 times
You could also go to:
http://www.matrixmultimedia.com/mmforum ... 891#p32952
Where you will find a post by Spanish_dude

Martin
Martin

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: BIT order LSB to MSB and vice versa

Post by JonnyW »

The link Martin posts to will work great if you are streaming your data (highest bit first).

If you want to invert a byte and store the new value you can do this in 1 calculation icon:

Code: Select all

  byte = (byte >> 7) | (byte >> 5) | (byte >> 3) | (byte >> 1) | (byte << 1) | (byte << 3) | (byte << 5) | (byte << 7)
This is then the inverted byte. You could put this call in a macro for ease of use (argument is byte, return is inverted byte). If you upgrade to v5, then you can use this macro call direct (for neatness) in decision icons, calculations, etc:

Code: Select all

  byte = invert(byte)
I hope this is useful.

Jonny

Dirk Bubley
Posts: 99
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Has thanked: 14 times
Been thanked: 12 times

Re: BIT order LSB to MSB and vice versa

Post by Dirk Bubley »

Hi Jonny,

your bit shift idea is looking good to me. Is this working in simulation too.

Because i feed the LCD Display with the new modified byte and i get strange results.


BR Dirk

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: BIT order LSB to MSB and vice versa

Post by JonnyW »

Ah, sorry! That's what I get for posting after my bedtime. That will not work at all, forget that code.

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
The code I posted would have 'smeared' the bits across the byte, instead of shifting them on their own. The '&' will isolate each bit correctly.

Jonny

Dirk Bubley
Posts: 99
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Has thanked: 14 times
Been thanked: 12 times

Re: BIT order LSB to MSB and vice versa

Post by Dirk Bubley »

Hi Jonny,

perfect it is working that solved my problem!! Many thanks!!

BR

Dirk

Post Reply