Reply to Re: Before...
If you don't have an account, just leave the password field blank.
This should do it. Please test it
// lets say, our &global is 0001 (1), and we want to
// change third bit, so it becomes 0101. This function must compute what
// number we get, when we change just this one tiny bit. In this case, output should be 5.
// We pass into the function which position we wanna change
// in this case, 3, and we pass whether we wanna change it into 1 or 0. In this case 1.
// &global is our global variable
// &arg1 = 3; &arg2 = 1;
// &counter will be 4, because we're dealing with 4 bits. But normally, it should loop 32 times,
// for 32 bit integer
void binary_change(3, 1)
{
// we copy the &global to &crap, and set &new_global for output
int &crap = &global;
int &new_global = 0;
// helping variables, since we cant have more operations at the same line
// &help is value of current remainder,
// &increment is value of current bit (at first position its 1, second position its 2, third position its 4...)
int &help = 0;
int &increment = 1;
int &counter = 4;
loop:
if(&counter > 0)
{
// until we don't reach the desired bit position, just compute global var value
// based on bits as they are
if(&counter != &arg1)
{
&help = math_mod(&crap);
// We compute the new value of &new_global, based on current bit. Like you would normally do on paper.
&help *= &increment;
&new_global += &help;
&increment *= 2; //multiply by two, I forgot the syntax
&counter -= 1;
}
// we came to bit we wanna change
else
{
&help = &arg2; // give the bit desired value
&help *= &increment; //calculate that value based on position, the rest is the same
&new_global += &help;
&increment *= 2;
&counter -= 1;
}
goto loop; //we still need to loop through remaining bits
}
else
{
return(&new_global); // all bits are looped through
}
}






