标题:求助:自学中题看不懂,看了书上的答案还是没看懂题,怎么办啊??
只看楼主
TAAAAB
Rank: 7Rank: 7Rank: 7
来 自:湖南
等 级:黑侠
威 望:1
帖 子:243
专家分:635
注 册:2011-5-29
结帖率:95.24%
已结贴  问题点数:20 回复次数:2 
求助:自学中题看不懂,看了书上的答案还是没看懂题,怎么办啊??
求解释这道题到底想做什么?

书中的编程练习题:


书中答案:
程序代码:
#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;
}
搜索更多相关主题的帖子: 练习题 做什么 color 
2015-04-29 11:15
TAAAAB
Rank: 7Rank: 7Rank: 7
来 自:湖南
等 级:黑侠
威 望:1
帖 子:243
专家分:635
注 册:2011-5-29
得分:0 
没人指点? 换一个问法,书中函数的第一个参数应该是什么内容??

人有多懒,编程就有多难。
2015-04-29 13:48
xumengxue
Rank: 2
等 级:论坛游民
帖 子:4
专家分:16
注 册:2015-4-29
得分:14 
我上次也遇到这种问题的,后来一个大神帮我解答的
2015-04-29 15:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-444639-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015222 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved