[Moved] can i have a c code for single bit flipping algorithm

Status
Not open for further replies.

Seetharavip

Newbie level 1
Joined
May 9, 2016
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
5
can someone
provide
c code for single bit flipping algorithm

[...email address deleted]
 
Last edited by a moderator:

Re: can i have a c code for single bit flipping algorithm

i think there are several examples of this online. You also might want to check compiler vendor info to see if a specific style is preferred. For example, x |= (1<<idx) will set a bit "idx" in x. A compiler might be able to do this with multiple instruction or a single specialized instruction on some platforms.

but overall, it is:
x |= (1<<idx); // set
x &= ~(1<<idx); //clear
x ^= (1<<idx); // toggle.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…