-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed one code clone and added 5 more
- Loading branch information
Showing
6 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} |