请使用按位取反ba_not和加法ba_add实现两个数的减法 提示 你可以使用int_to_ba_8函数获得常数1的bit_array表示ba8_t ba8_subba8_t a ba8_t b int tmp8 = 0 0 0 0 0 0 0 1 ; ba8_t ba_one = init_ba8tmp; TODO add you code here ba8_t
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; }
原文地址: http://www.cveoy.top/t/topic/cNVC 著作权归作者所有。请勿转载和采集!