Skip to content

Commit

Permalink
changed one code clone and added 5 more
Browse files Browse the repository at this point in the history
  • Loading branch information
MHutten committed Mar 8, 2021
1 parent 3768f1e commit aa8bcfa
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 4 deletions.
8 changes: 4 additions & 4 deletions samples/type2mod3.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// https://www.programiz.com/javascript/examples/decimal-binary
function convertToBinary(x) {
var bin = 0;
var rem, i = 1, step = 1;
let bin = {number: 0};
let rem, i = 1, step = 1;
while (x != 0) {
rem = x % 2;
console.log(`Step ${step++}: ${x}/2, Remainder = ${rem}, Quotient = ${parseInt(x/2)}`);
x = parseInt(x / 2);
bin = bin + rem * i;
bin[number] = bin[number] + rem * i;
i = i * 10;
}
console.log(`Binary: ${bin}`);
console.log(`Binary: ${bin[number]}`);
}
15 changes: 15 additions & 0 deletions samples/type2mod4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// https://www.programiz.com/javascript/examples/decimal-binary
function decimalToBinary(x) {
let bin = 0;
let ram = {}, i = 1, step = 1;

while (x != 0) { ram[remainder] = x % 2; // Added type 1 and type 2 changes

console.log(`Step ${step++}: ${x}/2, Remainder = ${ram[remainder]}, Quotient = ${parseInt(x/2)}`);
x = parseInt(x / 2);
bin = bin + ram[remainder] * i;

i = i * 10;
}
console.log(`Binary: ${bin}`);
}
14 changes: 14 additions & 0 deletions samples/type3mod1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// https://www.programiz.com/javascript/examples/decimal-binary
function convertToBinary(x, y) {
let bin = 0;
let rem, i = 1, step = 1;
while (x != 0) {
rem = x % 2;
console.log(`Step ${step++}: ${x}/2, Remainder = ${rem}, Quotient = ${parseInt(x/2)}`);
x = parseInt(x / 2);
bin = bin + rem * i;
i = i * 10;
y = y + 1;
}
console.log(`Binary: ${bin}`);
}
13 changes: 13 additions & 0 deletions samples/type3mod2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// https://www.programiz.com/javascript/examples/decimal-binary
function convertToBinary(x) {
let rem, i = 1, step = 1;
let bin = 0;
while (x != 0) {
rem = x % 2;
console.log(`Step ${step++}: ${x}/2, Remainder = ${rem}, Quotient = ${parseInt(x/2)}`);
bin = bin + rem * i;
i = i * 10;
x = parseInt(x / 2);
}
console.log(`Binary: ${bin}`);
}
13 changes: 13 additions & 0 deletions samples/type3mod3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// https://www.programiz.com/javascript/examples/decimal-binary
function convertToBinary(x) {
let bin = 0;
let rem, i = 1, step = 1;
while (x != 0) {
rem = x % 2;
console.log(`Step ${step++}: ${x}/2, Remainder = ${rem}, Quotient = ${parseInt(x/2)}`);
x = parseInt(x / 2);
bin += rem * i;
i *= 10;
}
console.log(`Binary: ${bin}`);
}
15 changes: 15 additions & 0 deletions samples/type3mod4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// https://www.programiz.com/javascript/examples/decimal-binary
function convertToBinary(x) {
let bin = 0;
let rem, i = 1, step = 1;
let bool = (x != 0)
while (bool) {
rem = x % 2;
console.log(`Step ${step++}: ${x}/2, Remainder = ${rem}, Quotient = ${parseInt(x/2)}`);
x = parseInt(x / 2);
bin = bin + rem * i;
i = i * 10;
bool = (x != 0)
}
console.log(`Binary: ${bin}`);
}

0 comments on commit aa8bcfa

Please sign in to comment.