c_cpp 练习最左边的c
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 练习最左边的c相关的知识,希望对你有一定的参考价值。
#include <stdio.h>
#include <limits.h>
// Bit shifting practice in C
void showbits(unsigned int x) {
for(int i = (sizeof(int) * 8) - 1; i >= 0; i--) {
(x & (1u << i)) ? putchar('1') : putchar('0');
}
printf("\n");
}
void show_binary_bools(unsigned int x) {
for(int i = (sizeof(int) * 8) - 1; i >= 0; i--) {
printf("This is raw shift %u\n", x & (1u << i));
printf("This is boolean result %d\n", (x & (1u << i)) ? 1 : 0);
}
}
int main(void) {
printf("Char bit size is %u\n", CHAR_BIT);
showbits(500);
show_binary_bools(500);
return 0;
}
以上是关于c_cpp 练习最左边的c的主要内容,如果未能解决你的问题,请参考以下文章
c_cpp C ++指针使用练习
c_cpp c中的void指针练习
c_cpp 地图练习
c_cpp 使用无序地图练习
c_cpp func指针练习
c_cpp 编程练习