Velocity Reviews > parsing #define in a code

parsing #define in a code

rahul8143@gmail.com
Guest
Posts: n/a

 10-04-2005
I have downlaoded one code from internet where i found one #define
statement
#define __fun32(x) ((_u32)( \
(((_u32)(x) & (_u32)0x000000ffUL) << 24) | \
(((_u32)(x) & (_u32)0x0000ff00UL) << | \
(((_u32)(x) & (_u32)0x00ff0000UL) >> | \
(((_u32)(x) & (_u32)0xff000000UL) >> 24) ))

what is the funtioning of this define function.

Kenneth Brody
Guest
Posts: n/a

 10-04-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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) << | \

Takes 0x0000nn00 and gives 0x00nn0000

> (((_u32)(x) & (_u32)0x00ff0000UL) >> | \

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.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <(E-Mail Removed)>

rahul8143@gmail.com
Guest
Posts: n/a

 10-04-2005

Kenneth Brody wrote:
> (E-Mail Removed) 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) << | \

>
> Takes 0x0000nn00 and gives 0x00nn0000
>
> > (((_u32)(x) & (_u32)0x00ff0000UL) >> | \

>
> 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?
>
> --
> +-------------------------+--------------------+-----------------------------+
> | Kenneth J. Brody | www.hvcomputer.com | |
> | kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
> +-------------------------+--------------------+-----------------------------+
> Don't e-mail me at: <(E-Mail Removed)>

Emmanuel Delahaye
Guest
Posts: n/a

 10-04-2005
(E-Mail Removed) wrote on 04/10/05 :
> I have downlaoded one code from internet where i found one #define
> statement
> #define __fun32(x) ((_u32)( \
> (((_u32)(x) & (_u32)0x000000ffUL) << 24) | \
> (((_u32)(x) & (_u32)0x0000ff00UL) << | \
> (((_u32)(x) & (_u32)0x00ff0000UL) >> | \
> (((_u32)(x) & (_u32)0xff000000UL) >> 24) ))
>
> what is the funtioning of this define function.

swap nibbles

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

..sig under repair

Keith Thompson
Guest
Posts: n/a

 10-04-2005
(E-Mail Removed) writes:
> Kenneth Brody wrote:
>> (E-Mail Removed) 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) << | \

>>
>> Takes 0x0000nn00 and gives 0x00nn0000
>>
>> > (((_u32)(x) & (_u32)0x00ff0000UL) >> | \

>>
>> 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

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) (E-Mail Removed) <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.