sum of two integers
生活随笔
收集整理的這篇文章主要介紹了
sum of two integers
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://leetcode.com/problems/sum-of-two-integers/
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.
Example:
Given a = 1 and b = 2, return 3.
注釋,這個題目有意思,學過FPGA的人都知道最基本的半加器和全加器是最基本的東西,這里也是這樣計算加法的。
int getSum(int a, int b) {if(b == 0)return a;int sum = a^ b;int cout = (a & b) << 1;return getSum(sum, cout); }總結
以上是生活随笔為你收集整理的sum of two integers的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python 数据科学入门
- 下一篇: 如何彻底删除sql2008