bit testing problem in mikroC for AVR

Status
Not open for further replies.

Noman Yousaf

Full Member level 4
Joined
Nov 19, 2003
Messages
208
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
Lahore Pakistan
Activity points
1,763
hi all
i am using mikro C for AVR.
how can i test or edit a bit in a variable int?like i have an 8 bit int "reg" and i want to make bit5 of "reg",hi. or i want to check the bit 5 is hi or low, for both cases, what i have to do? help please.
 

how can i test or edit a bit in a variable ?

Test bit 5:
Code:
if ( reg & 0b00100000 ) { //stuff here }
Edit bit 5:
Code:
reg |= 0b00100000 // Set bit
reg &= 0b11011111 // Clear bit
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…