num.js 201 B

123456789
  1. // 十进制转二进制
  2. export function decimalToBinary(decimal) {
  3. let binary = '';
  4. while (decimal > 0) {
  5. binary = (decimal % 2) + binary;
  6. decimal = Math.floor(decimal / 2);
  7. }
  8. return binary;
  9. }