标签:coding elf utf-8 bsp 取反 while subject color 异或
1 # -*- coding:utf-8 -*-
2 class Solution:
3 def Add(self, num1, num2):
4 # write code here
5 pos_sum = num1
6 while num2:
7 pos_sum = (num1^num2)& 0xffffffff
8 num2 = ((num1&num2)<<1)& 0xffffffff
9 num1 = pos_sum
10 if pos_sum <= 0x7fffffff:
11 return pos_sum
12 else:
13 return ~(pos_sum ^ 0xffffffff)
14
15
16
note:
0xffffffff表示-1 1111 1111 1111 1111 1111 1111 1111 1111(第一个1是符号位)
0x7fffffff表示最大正数,0111 1111 1111 1111 1111 1111 1111 1111(0是符号位)
对0取反为-1,对1取反为-2
标签:coding elf utf-8 bsp 取反 while subject color 异或
原文地址:https://www.cnblogs.com/shuangcao/p/12835592.html