Skip to content

Commit

Permalink
[NC] decimal to binary conversion DONE
Browse files Browse the repository at this point in the history
  • Loading branch information
SNP0301 committed Oct 30, 2023
1 parent 568de94 commit 9221452
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,21 @@ function decimalToBinary(d) {
while (true) {
if (d > 2 ** b_power - 1) {
b_power += 1;
console.log("b_power is: ", b_power);
} else {
console.log(d, "is greater than", 2 ** b_power);
break;
}
}
console.log("b power is: ", b_power);

for (var i = b_power - 1; i >= 0; i--) {
if (Math.floor(d / 2 ** i) == 1) {
b = b + "1";
d -= 2 ** i;
} else {
b = b + "0";
}
console.log(i, b);
}
console.log(b);
return b;
}

Expand Down

0 comments on commit 9221452

Please sign in to comment.