求助:自学中题看不懂,看了书上的答案还是没看懂题,怎么办啊??
求解释这道题到底想做什么?书中的编程练习题:
书中答案:
程序代码:
#include <limits.h> void set_bit(char bit_array[], unsigned bit_number); void clear_bit(char bit_array[], unsigned bit_number); void assign_bit(char bit_array[], unsigned bit_number, int value); int test_bit(char bit_array[], unsigned bit_number); unsigned character_offset(unsigned bit_number); unsigned bit_offset(unsigned bit_number); void set_bit(char bit_array[], unsigned bit_number) { bit_array[character_offset(bit_number)] |= 1 << bit_offset(bit_number); } void clear_bit(char bit_array[], unsigned bit_number) { bit_array[character_offset(bit_number)] &= ~(1 << bit_offset(bit_number)); } void assign_bit(char bit_array[], unsigned bit_number, int value) { if (value != 0) set_bit(bit_array, bit_number); else clear_bit(bit_array, bit_number); } int test_bit(char bit_array[], unsigned bit_number) { return ( bit_array[character_offset(bit_number)] & 1 << bit_offset(bit_number) ) != 0; } unsigned character_offset(unsigned bit_number) { return bit_number / CHAR_BIT; } unsigned bit_offset(unsigned bit_number) { return bit_number % CHAR_BIT; }