Decimal to binary

    0

    4

    My JavaScript recipes

    Convert a decimal number to binary

    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;
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.