ra*******@gmail.com writes:
Kenneth Brody wrote: ra*******@gmail.com wrote: >
> I have downlaoded one code from internet where i found one #define
> statement
> #define __fun32(x) ((_u32)( \
> (((_u32)(x) & (_u32)0x000000ffUL) << 24) | \
Takes 0x000000nn and gives 0xnn000000
> (((_u32)(x) & (_u32)0x0000ff00UL) << 8) | \
Takes 0x0000nn00 and gives 0x00nn0000
> (((_u32)(x) & (_u32)0x00ff0000UL) >> 8) | \
Takes 0x00nn0000 and gives 0x0000nn00
> (((_u32)(x) & (_u32)0xff000000UL) >> 24) ))
Takes 0xnn000000 and gives 0x000000nn
>
> what is the funtioning of this define function.
It reverses the byte order in a 32-bit value. For example, it turns
0xAABBCCDD into 0xDDCCBBAA.
Does that mean its the code for convert/reverse endianess? what is
final output for your inputs in above example is it 0xnnnnnnnn?
Well, if the input is 0xnnnnnnn, the output is 0xnnnnnnnn (assuming n
is a hexadecimal digit), but I don't think that's terribly useful.
Yes, it converts a little-endian 32-bit unsigned integer to
big-endian, or vice versa.
Given an input of 0x12345678, the result is 0x78563412. More
generally, given an input of 0xSTUVWXYZ, the result will be
0xYZWXUVST, where each of STUVWXYZ represents some arbitrary
hexadecimal digit.
Note that there's some missing context. The macro assumes that _u32
is a type name, presumably a typedef for a 32-bit unsigned integer.
Also, the identifier _u32 is reserved for use as an identifier with
file scope, and __fun32 is reserved for any use. If this macro is
part of the implementation, that's ok; otherwise, the author should
have chosen different names. (It's likely that this won't cause any
visible problems, unless the implementation happens to use those
names.)
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.