Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

How to convert LSB-MSB signal to MSB-LSB format?

Status
Not open for further replies.

woody28

Member level 3
Joined
Mar 24, 2002
Messages
64
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
450
Hi All

I am working on serial to parallel converter for RECS-80 protocol.
Bit order in received signal is LSB--> MSB and I want to convert it to
MSB-->LSB format.
So how can I do this in minimum :?: ? (Because my micro is 1k Flash) please give best a solution.

Example:
11000101 ---> 10100011

Best Regards
 

Maddin

Member level 5
Joined
Sep 26, 2001
Messages
94
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Europe
Activity points
842
convert msb lsb

Which MCU are you using? Maybe you will find the solution in the MCUs command set (or user manual) by checking the supported opcodes for shift / rotate (which can be inserted in your C / ASM code)
Hope it helped,
Maddin
 

Ace-X

Advanced Member level 2
Joined
Jan 25, 2002
Messages
529
Helped
41
Reputation
82
Reaction score
14
Trophy points
1,298
Location
Germany
Activity points
5,150
msb convert lsb

It depends on the instruction set of your uC. If it has the following commands:
- shift left
- shift right
- conditional jump (if negative)

then the best approach would be to make continious left shift of initial operand with conditional jump if the result of shifted operand was negative. If it was negative (it means that the current MSB=1) then you have to add 128 to result operand and shift it right, otherwise just shift it rigth without addition. After 8 cycles of this algorithm you will get the final result. For most uC this algorithm could be implemented in less then 10 instructions.

Ace-X.
 

C-Man

Advanced Member level 4
Joined
Jul 19, 2001
Messages
1,059
Helped
90
Reputation
180
Reaction score
17
Trophy points
1,318
Activity points
10,191
replace msb to lsb bits in c

unsigned char reverse(unsigned char normal)
{
unsigned char reversed

if(normal & 128)
reversed|=1;

if(normal & 64)
reversed|=2;


etc etc etc

return(reversed);
}

In most Micros this will compile to a Bit test and Bit set, hope this helps

regards
 

tom324

Full Member level 1
Joined
Jun 26, 2001
Messages
98
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Croatia
Activity points
672
what is lsb to msb

A bit more generic function, but for more powerfull uC.

typedef unsigned long T_u_int32; /* 32 bits unsigned */

T_u_int32 reverse_bits_test(T_u_int32 inval, int bits)
{
if ( bits > 0 )
{
bits--;
return reverse_bits_test(inval >> 1, bits) | ((inval & 1) << bits);
}
return 0;
}

Usage:

printf ("%04X\n", reverse_bits_test(0x2453, 16));

Tom
 

dirace

Member level 3
Joined
May 12, 2001
Messages
58
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,288
Activity points
411
shift right and replace msb

You can try this:

#include <math.h>

unsigned int i,Number,RevNumber;

i = 1;

RevNumber = (Number & 1)*128;

while (i<8)
{
RevNumber += (Number & pow(2,i))*(128/pow(2,i));
i++;
}
 

dirace

Member level 3
Joined
May 12, 2001
Messages
58
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,288
Activity points
411
convert lsb to msb

You can try this:

#include <math.h>

unsigned int i,Number,RevNumber;

i = 1;

RevNumber = (Number & 1)*128;

while ( i<8 ) // smaller than 8
{
RevNumber += (Number & pow(2,i))*(128/pow(2,i));
i++;
}
 

tom324

Full Member level 1
Joined
Jun 26, 2001
Messages
98
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Croatia
Activity points
672
msb lsb bit

Always replace pow(2,i) with 2 << (i-1) for i > 0 !!!

Tom
 

woody28

Member level 3
Joined
Mar 24, 2002
Messages
64
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
450
lsb msb convert

So many thanks to my best friends. :p

very useful solutions.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top