ba8_t ba8_sub(ba8_t a, ba8_t b) { int tmp[8] = { 0, 0, 0, 0, 0, 0, 0, 1 }; ba8_t ba_one = init_ba8(tmp); ba8_t b_neg = ba_not(b); ba8_t carry = ba_and(a, b_neg); ba8_t res = ba_add(a, b_neg); while (!ba_is_zero(carry)) { ba8_t shifted_carry = ba_shift_left(carry, 1); carry = ba_and(res, shifted_carry); res = ba_add(res, shifted_carry); } return res; }

使用按位取反和加法实现两个数的减法 (ba8_sub)

原文地址: https://www.cveoy.top/t/topic/nzGJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录