Continue to Site

# Some basic c questions plz with & and |

Status
Not open for further replies.

#### Terminator Electricity

##### Member level 5
what does this expressions mean ?
how are & and | used for different purposes ?
plz help cuz i really need to know this

EICRA &= ~0xf0;
EICRA |= 0xe0;

int newState = trans[State->state]>>Event & 0x3;

also ,, plz how >> or << are used and how many meanings they have

EICRA &= ~0xf0; is the abbreviated form of:
EICRA = EICRA & ~0xf0;
or
EICRA = EICRA & 0x0f;
So EICRA is read, ANDed with 0x0f, then written back to EICRA, in other words: the high nibble is cleared

similar in this expression:
EICRA |= 0xe0; is the abbreviated form of:
EICRA = EICRA | 0xe0;
So EICRA is read, ORed with 0xe0, then written back to EICRA, in other words: the 3 highest bits are set

The shift operators >> and <<:
better to write it like this (I'm too lazy to remember priorities ;-) )
int newState = (trans[State->state]>>Event) & 0x3;
means: trans[State->state] is shifted right "Event" times, then this value is ANDed with 0x03

<< means shift left. That's the only meaning I know of >> and <<

Points: 2