cancel
Showing results for 
Search instead for 
Did you mean: 

function for set reset

raducara
Associate II
Posted on July 17, 2013 at 11:03

HI , 

i have this function which sets x bit( passed as a parameter) of a byte . after some code the variable should be restored to it's initial value .

char a ; global variable 

void function(char x){

int b = a;

a |= (1<<x);  //set the x bit 

...some other code ....

a = b ;

}

So when i leave the function the value of a is restored to initial state . Is there any way i can optimize this (set reset procedure of a bit )?
1 REPLY 1
Posted on July 17, 2013 at 16:43

Decide to use int or char, then be consistent. I'd suggest that int being a native 32-bit representation would be more efficient.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..