模拟二进制实现减法
摘要:
#! /usr/bin/python# coding=utf-8import mathdef main(x,y): #对减数取反 x, y = bin(x)[2:], bin(y)[2:] l = max([len(x),len(y)]) #最大长度 #对y取反 y = "1" * (l - len(y)) + "".join(['1' if i == '0' else '0' for i in y]) x,y = int(x,2), int(y,2) z = x + y + 1 z = bin(z) #拿 阅读全文
posted @ 2012-11-30 14:18 Goodspeed 阅读(275) 评论(0) 推荐(0) 编辑