Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question about the "¦" sign and some more.

Status
Not open for further replies.

mojaffa

Programmer
Oct 23, 2003
8
SE
Could someone please help me understand how this works...

Defined in a header file:
Code:
#define	ETHCTRL	(*(IORegExt8)(IOBASE + 0))
#define	ETHWRITE (*(IORegExt8)(IOBASE + 1))
And in the program:
Code:
ETHCTRL = R_CR | R_NONE;
ETHWRITE = 0x00;
ETHCTRL = R_CR | (R_WR_OE & R_IOWR);
I know it sets registers in my ethernet controller(this is just a small part).
Since I want to change some settings of the ethernet ctrl I need to make some changes to this code, but I dont really get how this works. Particullary the "|" sign, what does it do?
TIA
Mojaffa
 
operator | sets the bits where the mask is 1 and leave intact where the mask is 0. Operator & reset the bits where the mask is 0 and leave intact where the mask is 1. Operator ^ invert all bits where the mask is 1 and leave intact where the mask is 0. Operator ~ inverts all bits. So, you should look at variables, write them in binary mode, and using above bit arythmetics, see what is the result. Bits also sometimes are named flags.

Ion Filipski
1c.bmp
 
The | sign is the OR operator in boolean algebra.

Code:
0 represents false value, and 1 represents true value.

0101011    
1001101
-------  OR
1101111


Irfin
 
Thanks.
Why didnt I see the connection to || that I use alot?
 
|| is not bitwise(bitlevel) operator, as well as &&.
For example -1 & 1234 is 1234, but -1 && 1234 is 1. At byte logical level (not bit level) -1, 1, 12345 is the same with any number which is not 0. There exist only 0 and everything else, but at bitlevel, operator is executed for each bit separately.

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top