Denary to binary
このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
これはまだ完了していないレッスンの先にある内容です。まずはそのレッスンを済ませてください:
Python Basics · Functions →
Denary to binary
Go the other way: from a denary number to its binary digits.
2で割り続けます。余り n % 2 が次のビットとなり、n // 2 がまだ変換すべき残り値です。余りは右から左へ現れるため、新しいビットを文字列の先頭に置きます。0 は独自の答えが必要で、ループが全く実行されないためです。
難易度 4/5 · 280 コイン + 今日初回達成時の小ボーナス
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" かつ 0 gives "0".
実行ボタンをクリックして出力を確認してください。