function convertToBinary(x) {
        let bin = 0;
        let rem, i = 1, step = 1;
        while (x != 0) {
          rem = x % 2;
          x = parseInt(x / 2);
          bin = bin + rem * i;
          i = i * 10;
        }
        return bin;
      }
      Javascript language logo

      Decimal to binary

      My JavaScript recipes

      Convert a decimal number to binary

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.