Binary to denary · แปลงไบนารีเป็นทศนิยม
Binary to denary
Convert a binary number, written as a string, to denary (base 10).
Read the bits from left to right. Each new bit doubles the value so far and then adds itself: for "101" the value goes 1, then 1 * 2 + 0 = 2, then 2 * 2 + 1 = 5. int("1") turns the character into the number 1.
Binary เป็น denary
แปลงเลข binary, เขียนเป็นสตริง, เป็น denary (base 10).
อ่านบิตจากซ้ายไปขวา. บิตใหม่แต่ละตัวจะคูณสองค่าที่มีอยู่แล้วแล้วบวกตัวเอง: สำหรับ "101" ค่าจะเปลี่ยนเป็น 1, แล้ว 1 * 2 + 0 = 2, แล้ว 2 * 2 + 1 = 5. int("1") เปลี่ยน character เป็น number 1.
Write to_denary(bits) that turns a string of 0s and 1s into its whole-number value, without using int(bits, 2). "1011" is 11. · เขียน to_denary(bits) ที่แปลงสตริงของ 0 และ 1 เป็นค่าเลขเต็ม โดยไม่ใช้ int(bits, 2). "1011" คือ 11
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่