phcbest 最近的时间轴更新
phcbest

phcbest

V2EX 第 578198 号会员,加入于 2022-04-14 10:24:40 +08:00
phcbest 最近回复了
```kotlin
fun add(a: Int, b: Int): Int {
var carry: Int
var sum: Int
do {
sum = a xor b
carry = (a and b) shl 1
a = sum
b = carry
} while (b != 0)
return a
}

fun subtract(a: Int, b: Int): Int {
return add(a, add(b.inv(), 1))
}

fun multiply(a: Int, b: Int): Int {
var result = 0
var shift = 0
var bCopy = b
while (bCopy != 0) {
if (bCopy and 1 == 1) {
result = add(result, a shl shift)
}
shift++
bCopy = bCopy shr 1
}
return result
}

fun divide(a: Int, b: Int): Int {
var dividend = a
var divisor = b
var quotient = 0
while (dividend >= divisor) {
dividend = subtract(dividend, divisor)
quotient = add(quotient, 1)
}
return quotient
}
```
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5603 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 12ms · UTC 08:50 · PVG 16:50 · LAX 01:50 · JFK 04:50
Developed with CodeLauncher
♥ Do have faith in what you're doing.