请使用按位取反ba_not和加法ba_add实现求一个数的相反数输入一个8位补码表示的数字x返回-x 的8位补码表示 即给定一个8位补码表示的数字x求 -x 的8位补码表示 提示 你可以使用int_to_ba_8函数获得常数的bit_array表示ba8_t ba8_negateba8_t a int tmp8 = 0 0 0 0 0 0 0 1 ; ba8_t ba_on
ba8_t ba8_negate(ba8_t a) { int tmp[8] = { 0, 0, 0, 0, 0, 0, 0, 1 }; ba8_t ba_one = init_ba8(tmp); ba8_t neg_a = ba_not(a); neg_a = ba_add(neg_a, ba_one); return neg_a; }
原文地址: https://www.cveoy.top/t/topic/cNV4 著作权归作者所有。请勿转载和采集!