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.

ไทย

Denary เป็น binary

ไปในทิศทางตรงกันข้าม: จากเลข denary เป็น digit binary ของมัน

หารด้วย 2 ซ้ำๆ ผลหารเหลือ n % 2 คือบิตถัดไป และ n // 2 คือส่วนที่เหลือที่จะแปลง ผลหารออกมาแบบ จากขวาไปซ้าย ดังนั้นให้วางบิตใหม่แต่ละตัวไว้ด้านหน้าของสตริง 0 ต้องการคำตอบของตัวเอง เพราะหากไม่เช่นนั้นลูปจะไม่มีวันทำงาน

Log in or create account · ⁨เข้าสู่ระบบหรือสร้างบัญชี⁩

IGCSE, A-Level & AP