题解 | #二进制转换#
二进制转换
https://www.nowcoder.com/practice/7b74386695cc48349af37196f45e62a8
思路:首先使用num.toString(radix)将num转换为radix进制的字符串,然后再使用循环不断在前填充字符0。
function convertToBinary(num) { let str=num.toString(2) while(str.length<8) str='0'+str return str }
总结:为什么padStart(8,'0')不能通过牛客编译器?
#二进制转换#前端js面试 文章被收录于专栏
前端js面试,帮助你更好的理解js。