Ejemplo n.º 1
0
MATRIX *MATRIX::DecimalToBinary(int val, int maxValue) {

	int power = 0;

	while ( (maxValue - pow(2.0,power)) >= 0 ) {

		power = power + 1;
	}

	MATRIX *binaryVal = new MATRIX(1,power,0);

	while ( val > 0 ) {

		power = 0;

		while ( (val - pow(2.0,power)) >= 0 ) {

			power = power + 1;
		}

		binaryVal->Set(0,binaryVal->width-power,1);
		val = val - int(pow(2.0,power-1));
	}

	return( binaryVal );
}
Ejemplo n.º 2
0
MATRIX *MATRIX::GetRow(int i) {

	MATRIX *row = new MATRIX(1,width);

	for (int currColumn=0;currColumn<width;currColumn++)
		row->Set(0,currColumn,Get(i,currColumn));

	return( row );
}
Ejemplo n.º 3
0
MATRIX *MATRIX::GetColumn(int j) {

	MATRIX *column = new MATRIX(length,1);

	for (int currRow=0;currRow<length;currRow++)
		column->Set(currRow,0,Get(currRow,j));

	return( column );
}
Ejemplo n.º 4
0
void MATRIX::SelectUniquelyFrom(int maxVal) {

	MATRIX *chosen = new MATRIX(1,maxVal,0);
	int j;
	int chosenVal;

	for (j=0;j<width;j++) {

		chosenVal = RandInt(0,maxVal-1);

		while ( chosen->Get(0,chosenVal) )
			chosenVal = RandInt(0,maxVal-1);

		Set(0,j,chosenVal);
		chosen->Set(0,chosenVal,1);
	}

	delete chosen;
	chosen = NULL;
}