Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

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

Status
Not open for further replies.

woody28

Member level 3
Member level 3
Joined
Mar 24, 2002
Messages
64
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
448
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
 

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
 

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.
 

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
 

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
 

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++;
}
 

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++;
}
 

msb lsb bit

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

Tom
 

how to convert lsb to msb

for MCS51 look at **broken link removed**
 

lsb msb convert

So many thanks to my best friends. :p

very useful solutions.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top