Ъγ:_小ツ雨oο
发表于 2018-6-17 14:57:38
真想知道
旧梦倾心
发表于 2018-6-18 17:32:29
248原则
LightyMi
发表于 2018-6-18 22:07:21
谢谢
xcf85532552
发表于 2018-6-19 20:25:01
朕想知道
开车蜗牛
发表于 2018-6-20 17:48:14
真想知道
夜の妖精
发表于 2018-6-20 21:02:35
朕想知道
落丶影灬
发表于 2018-6-21 23:15:00
朕想知道
wangmeng7756
发表于 2018-6-22 15:48:29
不想知道
SINOSMG
发表于 2018-6-23 16:25:44
{:5_94:}
822053080
发表于 2018-6-24 15:28:16
{:5_91:}
Spring_Rain
发表于 2018-6-24 18:00:44
尝试用python写了下十进制与二进制互相转换的程序:
十进制转二进制:
'''
功能为把十进制数转换为二进制数。
已完工。
作者:Spring Rain
'''
def go(start):
is_negative = False
is_first_1 = False
result = ""
process = []
num = int(start)
if num < 0:# 判断是否为负
is_negative = True
else:
result += "0"
num = int(start.replace("-", ""))
calculation_result = num
remainder = 0
while calculation_result >= 1:# 计算出二进制反序排列
remainder = calculation_result % 2
if remainder > 0:
process.append("1")
else:
process.append("0")
calculation_result = calculation_result // 2
the_len_of_calculation_result = len(process)
for i in range(1, len(process) + 1):# 将反序二进制转成正序二进制,并通过是否为负数进行第一位的控制
true_i = the_len_of_calculation_result - i
now = process
if now == "0" and is_negative and is_first_1 == False:
continue
elif is_negative:
is_first_1 = True
result += now
return result
if __name__ == "__main__":
start = input("请输入十进制数:")
result = go(start)
print(result)
二进制转十进制:
'''
功能为把二进制数转换为十进制数。
已完工。
作者:Spring Rain
'''
def go(num):
the_len = len(num)
result = ""
process = 0
for i in range(0, the_len):# 进行转换计算,即十进制数 == 依次将每个二进制位的值 * 2的位权次方再相加
now = int(num)
go = 2 ** (the_len-1-i)
process += now * go
if num == "1":# 检测符号位,1则为负,0则为正
result = "-" + str(process)
else:
result = str(process)
return result
if __name__ == "__main__":
start = input("请输入二进制数:")# get二进制数
result = go(start)# 调用函数
print("结果是", result)
Boomboomi
发表于 2018-6-25 19:37:22
郑真的很想知道
waw1228@qq.com
发表于 2018-6-25 21:09:12
朕当然想知道了
ahahazzxxff
发表于 2018-6-26 13:07:09
朕想知道
pastoralg
发表于 2018-6-27 12:58:12
朕想知道
yuandiyuandi123
发表于 2018-6-27 19:57:08
看答案
Assassin小白
发表于 2018-6-28 00:14:06
朕想知道
残梦洁月
发表于 2018-6-28 13:26:46
朕想知道
小尹同学
发表于 2018-6-29 14:53:07
快告诉我为什么
419167861
发表于 2018-6-29 17:40:21
郑想知道
{:10_249:}