473,396 Members | 1,886 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,396 software developers and data experts.

PORTA & 0x03 == 0x03

Hi,
I hope this is the right usenet group for posting this code...

IF (PORTA & 0x03 == 0x03) ...

... I want to verify if PORTA (0x00 to 0xFF) has bit 1 and bit 2 set to 1.

Is this the proper code?

Thanks
Jul 12 '06 #1
9 2966
sonos wrote:
I hope this is the right usenet group for posting this code...

IF (PORTA & 0x03 == 0x03) ...

.. I want to verify if PORTA (0x00 to 0xFF) has bit 1 and bit 2 set to 1.

Is this the proper code?
No. "if" must be lowercase. You must parenthesize to get the operation
you want:

if ((PORTA & 0x03) == 0x03) ...

--
Thad
Jul 12 '06 #2
Thad Smith wrote:
sonos wrote:
>I hope this is the right usenet group for posting this code...

IF (PORTA & 0x03 == 0x03) ...

.. I want to verify if PORTA (0x00 to 0xFF) has bit 1 and bit 2 set to 1.

Is this the proper code?

No. "if" must be lowercase. You must parenthesize to get the operation
you want:

if ((PORTA & 0x03) == 0x03) ...
And you don't /need/ to write the number in hex:

if ((PORTA & 3) == 3) ...

although your style may prefer it (especially if there are wider bit-patterns
around).

--
Chris "seeker" Dollin
A rock is not a fact. A rock is a rock.

Jul 12 '06 #3
sonos said:
Hi,
I hope this is the right usenet group for posting this code...

IF (PORTA & 0x03 == 0x03) ...
....looks oddly familiar. The same expression - and I mean precisely the same
expression - appeared in an OP a week or three ago.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 12 '06 #4
sonos posted:
Hi,
I hope this is the right usenet group for posting this code...

IF (PORTA & 0x03 == 0x03) ...

.. I want to verify if PORTA (0x00 to 0xFF) has bit 1 and bit 2 set to 1.

Is this the proper code?

No no on!

Open up your favourite operator precedence table:

http://www.difranco.net/cop2220/op-prec.htm

You'll notice that "==" has higher precedence than "&", so you'll need
parentheses.

if(3 == (PORTA & 3 ))

--

Frederick Gotham
Jul 12 '06 #5

"Chris Dollin" <ch**********@hp.comwrote in message
news:e9**********@malatesta.hpl.hp.com...
Thad Smith wrote:
>sonos wrote:
>>I hope this is the right usenet group for posting this code...

IF (PORTA & 0x03 == 0x03) ...

.. I want to verify if PORTA (0x00 to 0xFF) has bit 1 and bit 2 set to
1.

Is this the proper code?

No. "if" must be lowercase. You must parenthesize to get the operation
you want:

if ((PORTA & 0x03) == 0x03) ...

And you don't /need/ to write the number in hex:

if ((PORTA & 3) == 3) ...

although your style may prefer it (especially if there are wider
bit-patterns
around).
The OP said:
I want to verify if PORTA (0x00 to 0xFF) has bit 1 and bit 2 set to 1.

One could imply from this that the correct answer would be:
if ( PORTA & 3 ) ...
because the OP did not specify that ONLY bits 1 and 2 must be set.
>
--
Chris "seeker" Dollin
A rock is not a fact. A rock is a rock.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
Jul 12 '06 #6
Fred Kleinschmidt wrote:
The OP said:
I want to verify if PORTA (0x00 to 0xFF) has bit 1 and bit 2 set to 1.

One could imply from this that the correct answer would be:
if ( PORTA & 3 ) ...
because the OP did not specify that ONLY bits 1 and 2 must be set.

I think you had a brain fart. a & 3 will be true if a & 1 is true
and/or if a & 2 is true.

The two cases are

if ((a & 3) == a) { ... }

which means ONLY both bits are set and no others or

if ((a & 3) == 3) { ... }

which means that the two lower bits must be set

Tom

Jul 12 '06 #7
Tom St Denis wrote:
if ((a & 3) == a) { ... }

which means ONLY both bits are set and no others or
foot planted in mouth...

....

if (a == 3) { ... }

Teach me to be all superior. hehehehehe

Tom

Jul 12 '06 #8

"Tom St Denis" <to********@gmail.comha scritto nel messaggio
news:11**********************@35g2000cwc.googlegro ups.com...
Tom St Denis wrote:
if ((a & 3) == a) { ... }

which means ONLY both bits are set and no others or

foot planted in mouth...

...

if (a == 3) { ... }

Teach me to be all superior. hehehehehe

Tom
Not completely equivalent.

I presume 'a' and 'PORTA', see the OP question, are
device registers, probably declared with volatile.

Consequently

if (a == 3) {
/* ... */
}

is different from

if ((a & 3) == a) {
/* ... */
}

In second form the memory-mapped I/O port is read twice.
It can be important.
Giorgio Silvestri


Jul 12 '06 #9

"sonos" <so***@nospam.comschrieb im Newsbeitrag
news:d5******************************@giganews.com ...
Hi,
I hope this is the right usenet group for posting this code...

IF (PORTA & 0x03 == 0x03) ...

.. I want to verify if PORTA (0x00 to 0xFF) has bit 1 and bit 2 set
to 1.

Is this the proper code?
== comes before &, thus you want:
if ( (PORTA&0x03) == 0x03) ...
Jul 13 '06 #10

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

Similar topics

1
by: DrTebi | last post by:
Hello, I have the following problem: I used to "encode" my email address within links, in order to avoid (most) email spiders. So I had a link like this: <a...
0
by: Thomas Scheffler | last post by:
Hi, I runned in trouble using XALAN for XSL-Transformation. The following snipplet show what I mean: <a href="http://blah.com/?test=test&amp;test2=test2">Test1&amp;</a> <a...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
2
by: Damon | last post by:
I'm getting errors using XML deserialisation and CDATA sections when there are hexidecimal characters involved. If the CDATA section does not contain a hexidecimal values everything is fine....
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
12
by: InvalidLastName | last post by:
We have been used XslTransform. .NET 1.1, for transform XML document, Dataset with xsl to HTML. Some of these html contents contain javascript and links. For example: // javascript if (a &gt; b)...
7
by: John Nagle | last post by:
I've been parsing existing HTML with BeautifulSoup, and occasionally hit content which has something like "Design & Advertising", that is, an "&" instead of an "&amp;". Is there some way I can get...
1
by: Richard Eich | last post by:
gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-3) source snippet: .... int i = 17 ; if ( 0x03 & i ) ....
0
by: sopra_sotto | last post by:
Ciao a tutti e grazie per l'aiuto. problema. devo ricevere una striga su una porta tcp/ip da un programma scritto in Vb. in vb ho gia compilato tutto ma in c# ho molte difficolta. Come...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.