Skip to content

Denary to binary · ⁨十进制转二进制⁩

English

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.

中文

十进制转二进制

反过来转换:把十进制数变成二进制各位。

一次又一次地除以 2。余数 n % 2 是下一位,n // 2 是剩下还要转换的部分。余数是从右往左得到的,所以要把每个新的位加在字符串前面。0 需要单独处理,因为循环一次也不会运行。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩