Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > parsing #define in a code

Reply
Thread Tools

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.

 
Reply With Quote
 
 
 
 
Kenneth Brody
Guest
Posts: n/a
 
      10-04-2005
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: <private.php?do=newpm&u=>

 
Reply With Quote
 
 
 
 
rahul8143@gmail.com
Guest
Posts: n/a
 
      10-04-2005

Kenneth Brody wrote:
> 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: <private.php?do=newpm&u=>


 
Reply With Quote
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      10-04-2005
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


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-04-2005
writes:
> Kenneth Brody wrote:
>> 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
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) kst- <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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What libraries should I use for MIME parsing, XML parsing, and MySQL ? John Levine Ruby 0 02-02-2012 11:15 PM
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 09:01 PM
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 08:58 PM
SAX Parsing - Weird results when parsing content between tags. Naren XML 0 05-11-2004 07:25 PM
Perl expression for parsing CSV (ignoring parsing commas when in double quotes) GIMME Perl 2 02-11-2004 05:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57