我在整数数组中存储了一个“位”,例如
int a = {1,0,1,1}
我怎样才能将整数数组“bits”转换为unsigned char“bits”?
和互惠?
答案 0 :(得分:3)
int int_array[] = {1, 0, 1, 1};
unsigned char uc_array[sizeof int_array / sizeof *int_array];
for (size_t i = 0; i != sizeof int_array / sizeof *int_array; ++i)
uc_array[i] = int_array[i];
(您的示例代码存在缺陷:标量变量的初始化程序太多)