Binary to denary · 二进制转十进制
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
This one builds on a lesson you haven't finished yet. Do that lesson first: · 此任务基于您尚未完成的课程。请先完成以下课程:
Python Basics · Python 基础 · Functions · 函数 →
English
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.
中文
二进制转十进制
把写成字符串的二进制数转换成十进制数。
从左到右读取每一位。每读一位,就把目前的值乘以 2,再加上这一位:对于 "101",值依次是 1、1 * 2 + 0 = 2、2 * 2 + 1 = 5。int("1") 把字符变成数字 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. · 点击“运行”查看此处输出。