hi I wanted to convert Little Endian to big endian for 2 byte value
for example
if hex value of aValue = 0102
required valu e = 0201
Firstly make sure that you use unsigned types for bit manipulation liek
this, the rules for signed types don't guarantee the results you expect or
even that the operation is well defined.
This can be done
bValue = ( (aValue << 8) | (aValue << 8))
I take it you mean
bValue = ( (aValue << 8) | (aValue >> 8));
Don't assume the type you are using is exactly 16 bits, C generally
specifies MINIMUM ranges for types, they can be wider. So
bValue = ( ((aValue & 0xff) << 8) | (aValue >> 8));
or belts and braces:
bValue = ( ((aValue & 0xff) << 8) | ((aValue >> 8) & 0xff));
Note also that C doesn't require a byte to be 8 bits, it can have more.
Maybe what you are doing only makes sense if it is, but if you wanted to
use the more general C definition of a byte you could use for example
#include <limits.h>
bValue = ( ((aValue & UCHAR_MAX) << CHAR_BIT) |
((aValue >> CHAR_BIT) & UCHAR_MAX) );
But how about if value is bValue = F26B I am getting FFF2 instead of
6BF2
You were probably using a signed integer type. A common implementation
for right shifting signed values is to use "sign extension", i.e. instead
of shifting zeroes in from the left the sign bit is duplicated.
Lawrence