GIP 9
#include 
#include 
using namespace std;
int power_of(int basis, int exponent=2)
{
	long int retur = basis; 
	if(basis == 0)
		return false;
	
	for( int i=1; i <= exponent; i++ )
		retur = retur * basis;
	return retur;
}
int biner(int zahl)
{
	const short binerstellen = 8;
	int max = power_of( 2, binerstellen );
	//cout << max << endl;	
	long int bin = 0;
	for( int i=binerstellen; i>=0; i-- )
	{
		if(zahl >= max)
		{
			bin = bin + power_of(10, i);			
		}
		cout << bin << " -> " << i << endl;
		
		max = max / 2;
	}
	return bin;
}
int oktal(int zahl)
{
	//string oktalziffer[8]={"0","1","2","3","4","5","6","7"};
	return 0;	
}
int main(void)
{
	int zahl;
	cout << "Dezimalzahl = ? ";
	cin >> zahl;
	cout << "Umrechnung einer ganzzahligen, positiven Dezimalzahl in" << endl << 
			"- eine Dualzahl nach der Potenzenmethode : Dualzahl    = " << biner(zahl) << endl <<
			"- eine Oktalzahl nach der Restwertmethode: Oktalzahl   = " << oktal(zahl) << endl;
	return 0;
}
Veröffentlicht am: 03.12.2007 von: CHR |  publiziert in: C, FH-Aachen