Here's the code :
private int BinToDec(bool[] bin, int lenght) {
int i, dec;
for(i = 0; i = lenght; i++){
if(bin[lenght - i] = true){
dec += Math.pow(2, i);
}
}
return dec;
}
private bool[] DecToBin(int dec){
bool match;
int lenght;
while(!match){
if(dec < Math.pow(2, i)){
match = true;
break;
}
lenght++;
}
bool[] bin[lenght-1];
int power = lenght;
for(;lenght = 0; lenght--){
if(BinToDec(bin, lenght-1) + Math.pow(2, lenght) < dec){
bin[lenght] = true;
}
if(BinToDec(bin, lenght-1) == dec) return bin;
}
}


Sign In
Create Account

Back to top









