The Dink Network

toof's Profile

duck.gif
toof
Peasant Male
I disagree. 
My biography is classified, 'cause it's classy.

Web Page http://toof17.github.io/toofweb/
Private Message

2018-10-21 10:20:19
duck.gif
toof
Peasant Male
I disagree. 
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
	}
}

toof has released 3 files

TitleCategoryAvgUpdated
Dink Hotel (The)D-Mod, RompGood 7.1April 2nd, 2019
Golden DuckD-Mod, RompGood 8.7October 4th, 2018
DinkC Syntax Highlighting for Notepad++ DarkDevelopment, UtilityN/AJuly 18th, 2018

toof has written 2 reviews

TitleFileTypeScoreDate
In a gadda da Brassweasel... Search (The)NormalGood 8.3October 1st, 2018
The good, the bad, and the this review The DiscipleFeaturedExceptional 9.2September 18th, 2017