255) { return ''; } else { string bin; int oneorzero; for(int i=8;i>0;i--) { oneorzero = v % 2; if (oneorzero == 1) { bin = '1' + bin; } else { bin = '0' + bin; } v /= 2; } return bin; } } int main(){ int v; do { cout <> v)) { return 0; } if (v 255) { return ''; } else { string bin; int oneorzero; for(int i=8;i>0;i--) { oneorzero = v % 2; if (oneorzero == 1) { bin = '1' + bin; } else { bin = '0' + bin; } v /= 2; } return bin; } } int main(){ int v; do { cout <> v)) { return 0; } if (v Simple C++ dec2bin program @KTSI - Thomas Maurer

Written by 11:00 am School

Simple C++ dec2bin program @KTSI

This is a very simple dec2bin program done for KTSI.

#include 
#include 
#include 
 
using namespace std;
 
string dec2bin (int v) {
	if (v &gt; 255) {
		return "";
	}
	else { 
		string bin;
		int oneorzero;
		for(int i=8;i&gt;0;i--) {
			oneorzero = v % 2;
			if (oneorzero == 1) {
				bin = "1" + bin;
			}
			else {
				bin = "0" + bin;
			}
			v /= 2;
 
		}
 
	return bin;
 
	}
}
 
int main(){
    int v;
    do {
        cout &lt;&lt; "Wert(ende = -1) = "; if (!(cin &gt;&gt; v)) {
            return 0;
        }
        if (v &lt; 0) break;
        string s = dec2bin(v);
        cout &lt;&lt; s &lt;&lt; endl; //system("PAUSE"); } while(v &gt;= 0);
    cout &lt;&lt; "bye" &lt;&lt; endl;
    //system("PAUSE");
    return 0;
}

Tags: , , , , , , , Last modified: July 5, 2019
Close Search Window
Close