Skip to main content
Mod Removes Wiki by Makyen
Post Made Community Wiki by Makyen
deleted 11 characters in body
Source Link
ganesh phirke
  • 473
  • 1
  • 3
  • 12

we can also calculate the binary for positive or negative numbers as below:

function toBinary(n){
    let binary = "";
    if (n < 0) {
      n = 0xFFFFFFFF + n +>>> 1;0;
    }
    while(Math.ceil(n/2) > 0){
        binary = n%2 + binary;
        n = Math.floor(n/2);
    }
    return binary;
}

console.log(toBinary(7));
console.log(toBinary(-7));

we can also calculate the binary for positive or negative numbers as below:

function toBinary(n){
    let binary = "";
    if (n < 0) {
      n = 0xFFFFFFFF + n + 1;
    }
    while(Math.ceil(n/2) > 0){
        binary = n%2 + binary;
        n = Math.floor(n/2);
    }
    return binary;
}

console.log(toBinary(7));
console.log(toBinary(-7));

we can also calculate the binary for positive or negative numbers as below:

function toBinary(n){
    let binary = "";
    if (n < 0) {
      n = n >>> 0;
    }
    while(Math.ceil(n/2) > 0){
        binary = n%2 + binary;
        n = Math.floor(n/2);
    }
    return binary;
}

console.log(toBinary(7));
console.log(toBinary(-7));

added 100 characters in body
Source Link
ganesh phirke
  • 473
  • 1
  • 3
  • 12

we can also calculate the binary for positive or negative numbers as below:

function toBinary(n){
    let binary = "";
    if (n < 0) {
      n = 0xFFFFFFFF + n + 1;
    }
    while(Math.ceil(n/2) > 0){
        binary = n%2 + binary;
        n = Math.floor(n/2);
    }
    return binary;
} 

console.log(toBinary(7));
console.log(toBinary(-7));

we can also calculate the binary for positive numbers as below:

function toBinary(n){
    let binary = "";
    while(Math.ceil(n/2) > 0){
        binary = n%2 + binary;
        n = Math.floor(n/2);
    }
    return binary;
}

console.log(toBinary(7));

we can also calculate the binary for positive or negative numbers as below:

function toBinary(n){
    let binary = "";
    if (n < 0) {
      n = 0xFFFFFFFF + n + 1;
    }
    while(Math.ceil(n/2) > 0){
        binary = n%2 + binary;
        n = Math.floor(n/2);
    }
    return binary;
} 

console.log(toBinary(7));
console.log(toBinary(-7));

Source Link
ganesh phirke
  • 473
  • 1
  • 3
  • 12

we can also calculate the binary for positive numbers as below:

function toBinary(n){
    let binary = "";
    while(Math.ceil(n/2) > 0){
        binary = n%2 + binary;
        n = Math.floor(n/2);
    }
    return binary;
}

console.log(toBinary(7));