Esempio n. 1
0
str strDecToStrBin(str dec){
    str bin="";
    int m=dec.size();
    int i=0;
    while(dec.size()){
        //printf("DEC %s\n", dec.c_str());
        char l=dec.at(dec.size()-1);
        if(l=='0' || l=='2' || l=='4' || l=='6' || l=='8'){ //parzysta
            bin='0'+bin;
        }else{
            bin='1'+bin;
        }
        dec=divideByTwo(dec);
        if(dec.at(0)=='0'){dec.erase(0,1);}
    }
    return bin;
}
Esempio n. 2
0
void binaryNumberToCode(str bin){
    vec<str> v;
    addCodeLine("ZERO");
    //printf("ZMIANA\n");
    while(bin!="0"){
        //printf("BIN %s\n", bin.c_str());
        char l=bin.at(bin.size()-1);
        if(l=='1'){
            v.push_back("INC");
            bin.at(bin.size()-1)='0';
        }else if(l=='0'){
            v.push_back("SHL");
            bin.erase(bin.size()-1, 1);
        }
    }
    for(int i=v.size()-1; i>=0; i--){
        addCodeLine(v.at(i));
	}
}