At first there are two unsigned long long int variables A and B equal to each other. A is used in a function that changes the bit in the position N (from right to left starting at 0) from 0 to 1 by doing A += C, where C is 2^N and is already calculated. Then I have to make A equal to B again.
Two trivial codes come to mind:
1 2
function(N); // A is changed
A = B;
and
1 2
function(N); // A is changed
A -= C;
I want to know which of these is faster and also if there is another, more advanced, way even faster.
What is purpose of skipping few processor commands? "faster" in this case is not really faster - you will(most likely) not notice difference, and if it's processed several times(millions, maybe more) - then eventual difference will be still less than I second - at least that's most likely.
Probably A = B will be faster, because you will not have to do subtraction operation, but that's not an optimization you should look for.
PS. Also, why change A when you have to reset it after function is done? If you want to change N, change N, not A. If you are using pointer, maybe pass A by value instead of passing A by pointer or reference?