Denary to binary
Denary to binary
Go the other way: from a denary number to its binary digits.
Divide by 2 again and again. The remainder n % 2 is the next bit, and n // 2 is what is left to convert. The remainders come out right to left, so put each new bit at the front of the string. 0 needs its own answer, because the loop would never run.
진법수를 이진수로 변환
반대로 진행하십시오: 진법수에서 이진수 digit들까지.
2으로 계속 나누십시오. 나머지 n % 2이 다음 비트가 되고, n // 2는 아직 변환하지 않은 나머지 값입니다. 나머지는 오른쪽에서 왼쪽으로 나오므로, 새로운 비트마다 문자열 맨 앞에 추가하십시오. 0은 자체 답안이 필요하며, 루프가 실행되지 않기 때문입니다.
Write to_binary(n) that returns the binary digits of a whole number n (0 or more) as a string, without using bin(). 11 gives "1011" and 0 gives "0".
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.