简体   繁体   English

编写一个返回16位表达式的函数

[英]Writing a function that returns 16-bit expression

The question following is excerpted from exercise 6, chapter 7, A book on C. 以下问题摘自练习6,第7章,关于C的书。

  1. Write a function that will extract every other bit position from a 32-bit expression. 编写一个函数,从32位表达式中提取每个其他位的位置。 The result should be returned as a 16-bit expression. 结果应作为16位表达式返回。 Your function should work on machines having either 2- or 4-byte words. 您的功能应该适用于具有2字节或4字节字的计算机。

Now there are two key points I do not understand about this question: 现在关于这个问题我有两点不明白:

  • What does it mean, "extract every other bit position"? 这是什么意思,“提取其他所有位置”? I really do not understand this. 我真的不明白这一点。 For example, a 32-bit expression: 00000001 00000000 00000000 10011110, what can "extract every other bit position" do? 例如,32位表达式:00000001 00000000 00000000 10011110,什么可以“提取其他位位置”呢?
  • The question seems to contradict itself: "Extract every other bit position from a 32-bit expression," then "your function should work on machines having either 2- or 4-byte words," but 2-byte words are only 16-bit expression; 这个问题似乎与自己相矛盾:“从32位表达式中提取每个其他位的位置”,然后“你的函数应该在具有2或4字节字的机器上运行”,但是2字节字只有16位表达; how can I extract every other bit position from an expression that is "both" 32-bit and 16-bit? 如何从“32位”和“16位”两个表达式中提取每个其他位位置?

This question really makes no senses. 这个问题确实没有任何意义。 One of the things I really hate about this book is, compared to C prorgamming written by Kochan, which I have no problems at all in understanding its questions, so dense to understand with respect to exercise questions. 与Kochan撰写的C prorgamming相比,我真正讨厌这本书的其中一件事是,我在理解它的问题时没有任何问题,因此对于运动问题的理解非常密集。 Or may be I am just stupid! 或者可能是我只是愚蠢!

"every other bit" means each either bits 0, 2, 4, 6 ... or bits 1, 3, 5, 7 ... “每隔一位”表示每个位0,2,4,6 ...或位1,3,5,7 ......

If you start with 32 bits and take each other bit then your result is 16 bits. 如果从32位开始并相互取位,则结果为16位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM