摘要: c语言中整数的显示 以十进制、二进制、八进制、十六进制显示整数 1、 #include <stdio.h> int count_bits(unsigned x) { int bits = 0; while(x) { if(x & 1U) bits++; x >>= 1; } return bits; 阅读全文
posted @ 2021-05-19 22:50 小鲨鱼2018 阅读(442) 评论(0) 推荐(0) 编辑
摘要: 编写inverse_n函数,返回将无符号整数x的第pos为开始的n位取反后的值。 1、 #include <stdio.h> unsigned inverse_n(unsigned x, int pos, int n) { int i; for(i = pos; i <= pos + n - 1; 阅读全文
posted @ 2021-05-19 19:06 小鲨鱼2018 阅读(69) 评论(0) 推荐(0) 编辑
摘要: 编写reset_n函数,返回将无符号整数x的第pos为开始的n位设为0后的值。 1、 #include <stdio.h> unsigned reset_n(unsigned x, int pos, int n) { int i; for(i = pos; i <= pos + n - 1; i++ 阅读全文
posted @ 2021-05-19 18:44 小鲨鱼2018 阅读(61) 评论(0) 推荐(0) 编辑
摘要: 编写set_n函数,返回将无符号整数x的第pos位到第pos + n - 1 位的 n 位 设为1后的值。 1、 #include <stdio.h> unsigned set_n(unsigned x, int pos, int n) { int i; for(i = pos; i <= pos 阅读全文
posted @ 2021-05-19 18:14 小鲨鱼2018 阅读(52) 评论(0) 推荐(0) 编辑
摘要: 编写reverse函数,返回将无符号整数x的第pos位取反后的值。 1、 #include <stdio.h> unsigned reverse(unsigned x, int pos) { if(x >> pos & 1U) return (x & (~(1 << pos))); else ret 阅读全文
posted @ 2021-05-19 17:36 小鲨鱼2018 阅读(47) 评论(0) 推荐(0) 编辑
摘要: 编写reset函数,返回无符号整数x的第pos为设为0后的值。 1、 #include <stdio.h> unsigned reset(unsigned x, int pos) { return (x & (~(1 << pos))); } int main(void) { unsigned x; 阅读全文
posted @ 2021-05-19 16:39 小鲨鱼2018 阅读(43) 评论(0) 推荐(0) 编辑
摘要: 编写函数,返回将无符号整数的第pos位设置为1后的值。 1、 #include <stdio.h> unsigned set(unsigned x, int pos) { return (x | 1 << pos); } int main(void) { unsigned x; int n; put 阅读全文
posted @ 2021-05-19 13:02 小鲨鱼2018 阅读(56) 评论(0) 推荐(0) 编辑