C语言中在二进制数末尾追加一位
我想用C语言向二进制数添加一位,我对C语言很陌生,所以请不要因为这样的问题来评判我。我会很高兴,答案会非常有帮助:) 这是我的代码块:
void helloworldToBinary () {
int i;
char *string = "hello world";
for(i = 0 ; i < 8 * strlen(string); i++)
printf("%d", 0 != (string[i/8] & 1 << (~i&7)));
printf("\n");
}
如果有帮助,这就是现在的输出:
0110100001100101011011000110110001101111001000000111011101101111011100100110110001100100
这是我想要的输出:
01101000011001010110110001101100011011110010000001110111011011110111001001101100011001001
I'd like to add one single bit to a binary number in C, I'm pretty new to C, so please don't judge me because of such questions. I'd be very happy and a answer would be very helpful :)
Here's my code block:
void helloworldToBinary () {
int i;
char *string = "hello world";
for(i = 0 ; i < 8 * strlen(string); i++)
printf("%d", 0 != (string[i/8] & 1 << (~i&7)));
printf("\n");
}
If it helps, this is the output now:
0110100001100101011011000110110001101111001000000111011101101111011100100110110001100100
And this is the Output I'd want:
01101000011001010110110001101100011011110010000001110111011011110111001001101100011001001
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论