programme python

Addition en binaire:


c = 0

r = [0,0,0,0,0,0,0,0,0,0,0]

#n =[True,False,True,False,True,False,True,False,True,False]

#p =[True,False,True,False,True,False,True,False,True,False]

n = [1,0,1,0,1,0,1,0,1,0]

p = [1,0,1,0,1,0,1,0,1,0]

for i in range(9,-1,-1):

      a=n[i]

      b=p[i]

      print (i)

      r[i+1]=(a and (not b) and (not c)) or ((not a) and b and (not c)) or ((not a) and (not b) and c) or (a and b and c)

      c=(a and b) or (b and c) or (a and c)

r[0]=c

print (r)


a="1010101010"

b="1010101010"

sum= bin(int(a,2)+int(b,2))

print (sum)


Explications:

il y a po

Créez votre site web gratuitement ! Ce site internet a été réalisé avec Webnode. Créez le votre gratuitement aujourd'hui ! Commencer