比特掩蔽 [英] bit masking

查看:67
本文介绍了比特掩蔽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近的一个主题讨论了以特定顺序将4个给定字节转换为

长。在研究这个时,我遇到了K&R§2.9,其中以下

表达式被认为掩盖了除前七位以外的所有内容:


n = n &安培; 0177;


如果1 + 2 + 4 + ... + 64(七个术语)等于

除了127以外的东西,这对我来说似乎是对的想法? MPJ

解决方案

Merrill& Michele写道:

最近的一个主题讨论了将特定顺序中的4个给定字节转换为
long。在研究这个时,我遇到了K&R§2.9,其中以下
表达式被认为掩盖了除前七位以外的所有内容:

n = n& 0177;

如果1 + 2 + 4 + ... + 64(七个术语)等于除了127以外的其他东西,这对我来说似乎是正确的。想法? MPJ



以0开头的数字是八进制的。例如:


0177 == 127

026 == 22

011 == 9

等等。


HTH,

- g


-

Artie Gold - 德克萨斯州奥斯汀


如果你不认为这很重要,你就不会注意了。




" Merrill&米歇尔" <是******** @ comcast.net>在消息中写道

news:dN ******************** @ comcast.com ...

A最近的讨论讨论了将特定顺序的4个给定字节转换为
long。在研究这个时,我遇到了K&R§2.9,其中以下
表达式被认为掩盖了除前七位以外的所有内容:

n = n& 0177;

如果1 + 2 + 4 + ... + 64(七个术语)等于除了127以外的其他东西,这对我来说似乎是正确的。想法? MPJ




0177(以及以数字0开头的任何整数字面数)

在基数8中。就个人而言,我更喜欢使用十六进制常量

(0x前缀)表示位模式(我可以更容易地/ b $ b精神上将它们转换成二进制)。


-Mike


" Mike Wahler" < MK ****** @ mkwahler.net>在消息新闻中写道:< dT *************** @ newsread3.news.pas.earthli nk.net> ...


0177(以及以数字0开头的任何整数文字)
位于基数为8。




注意尽管pp-number令牌没有一个基地。像

0188这样的标记是完全有效的,可以和宏操作员一起使用。


-

彼得


A recent thread discussed turning 4 given bytes in a particular order to a
long. While studying this, I encountered K&R §2.9, where the following
expression is said to mask off all but the first seven bits:

n=n & 0177;

This would have seemed right to me if 1+2+4+...+64 (seven terms) equaled
something other than 127. Ideas? MPJ

解决方案

Merrill & Michele wrote:

A recent thread discussed turning 4 given bytes in a particular order to a
long. While studying this, I encountered K&R §2.9, where the following
expression is said to mask off all but the first seven bits:

n=n & 0177;

This would have seemed right to me if 1+2+4+...+64 (seven terms) equaled
something other than 127. Ideas? MPJ


Numbers that start with `0'' are in octal. As examples:

0177 == 127
026 == 22
011 == 9

and so on.

HTH,
--ag

--
Artie Gold -- Austin, Texas

"If you don''t think it matters, you''re not paying attention."



"Merrill & Michele" <be********@comcast.net> wrote in message
news:dN********************@comcast.com...

A recent thread discussed turning 4 given bytes in a particular order to a
long. While studying this, I encountered K&R §2.9, where the following
expression is said to mask off all but the first seven bits:

n=n & 0177;

This would have seemed right to me if 1+2+4+...+64 (seven terms) equaled
something other than 127. Ideas? MPJ



0177 (and any integer literal beginning with digit ''0'')
is in base 8. Personally, I prefer to use hex constants
("0x" prefix) for expressing bit patterns (I can more readily
mentally convert them to/from binary).

-Mike


"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<dT***************@newsread3.news.pas.earthli nk.net>...


0177 (and any integer literal beginning with digit ''0'')
is in base 8.



Note though that pp-number tokens do not have a base. A token like
0188 is perfectly valid and could be used with macro operators.

--
Peter


这篇关于比特掩蔽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆