Changing endianess

03 Mar 2015

I am having trouble changing the endian of a variable.

First, I have two bytes that I want to combine to form a short. I have been able to do this by:

s = (b1 * 256) + b2;

Now, I want to swap all of the bits so that "s" that initially equals:

1100000000000010

becomes

0100000000000011

I would like to do it "simpler" than a line of code per bit if possible....

03 Mar 2015

When developing with our Astrobe Oberon language system you can use the SYSTEM function RBIT to reverse all the bits in a word. e.g.

s := SYSTEM.RBIT(s);

It generates a single inline Cortex-M3 instruction to perform the operation.

If you are programming in C the most efficient way would be to implement it as an inline assembly language call to use the corresponding RBIT instruction.

Regards, Chris Burrows CFB Software http://www.astrobe.com

03 Mar 2015

One addition to Chris' answer: There is no need to add an inline assembly call yourself, just use the C-function:

uint32_t __RBIT(uint32_t value) 

That will insert the required assembly for you.