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
BIT order LSB to MSB and vice versa
Moderator: Benj
-
Dirk Bubley
- Posts: 99
- Joined: Fri Feb 02, 2007 3:54 pm
- Location: Germany
- Has thanked: 14 times
- Been thanked: 12 times
-
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
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: You could also go to:
http://www.matrixmultimedia.com/mmforum ... 891#p32952
Where you will find a post by Spanish_dude
Martin
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: You could also go to:
http://www.matrixmultimedia.com/mmforum ... 891#p32952
Where you will find a post by Spanish_dude
Martin
Martin
- 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
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:
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:
I hope this is useful.
Jonny
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)Code: Select all
byte = invert(byte)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
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
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
- 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
Ah, sorry! That's what I get for posting after my bedtime. That will not work at all, forget that code.
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
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) & 0x80Jonny
-
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
Hi Jonny,
perfect it is working that solved my problem!! Many thanks!!
BR
Dirk
perfect it is working that solved my problem!! Many thanks!!
BR
Dirk