473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

parsing #define in a code

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) << 8) | \
(((_u32)(x) & (_u32)0x00ff0000UL) >> 8) | \
(((_u32)(x) & (_u32)0xff000000UL) >> 24) ))

what is the funtioning of this define function.

Nov 15 '05 #1
4 2867
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.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Nov 15 '05 #2

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?
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>


Nov 15 '05 #3
ra*******@gmail.com 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) << 8) | \
(((_u32)(x) & (_u32)0x00ff0000UL) >> 8) | \
(((_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
Nov 15 '05 #4
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.
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
7
by: Kylotan | last post by:
I have a text file where the fields are delimited in various different ways. For example, strings are terminated with a tilde, numbers are terminated with whitespace, and some identifiers are...
8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
10
by: george young | last post by:
For each run of my app, I have a known set of (<100) wafer names. Names are sometimes simply integers, sometimes a short string, and sometimes a short string followed by an integer, e.g.: 5, 6,...
4
by: ralphNOSPAM | last post by:
Is there a function or otherwise some way to pull out the target text within an XML tag? For example, in the XML tag below, I want to pull out 'CALIFORNIA'. ...
14
by: Arthur J. O'Dwyer | last post by:
Well, I'm trying to write that program that was requested a few weeks back, the one that could take struct definitions and create portable functions to read and write those structs. Hence the...
4
by: Hugh | last post by:
Hello, I am having some problems understanding (most likely), parsing a text file. I would like to parse a file like: block1 { stuff; ... stuffN; };
2
by: uche | last post by:
Guys, I am trying to build a Parse Tree with the following grammar. I have implemented my insertions using a standard binary tree inserting algorithm. With the psuedocode below, can you guys...
2
by: python | last post by:
I'm parsing a text file for a proprietary product that has the following 2 directives: #include <somefile> #define <name<value> Defined constants are referenced via <#name#syntax. I'm...
5
by: Luis Zarrabeitia | last post by:
I need to parse a file, text file. The format is something like that: TYPE1 metadata data line 1 data line 2 .... data line N TYPE2 metadata data line 1 ....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.