题解 | #二进制转换#

二进制转换

https://www.nowcoder.com/practice/7b74386695cc48349af37196f45e62a8

      function convertToBinary(num) {
        let a = num;
        let res = "";
        while (a >= 1) {
          res = (a % 2) + res;
          if (a % 2) a--;
          a /= 2;
        }
        // console.log(res);
        for (let i = 8 - res.length; i; --i) res = 0 + res;
        return res;
      }

全部评论

相关推荐

08-05 18:14
门头沟学院 Java
小花的沉默:是学历厂没错啊,学历太高了不要
投递小鹏汽车等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务