基本位操作问题。 [英] Basic Bit Operation Question.

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

问题描述

大家好,


我得到了一个非常基本的问题,我在这里:


假设我有11001 11010位是真的10位。现在我想

地址,所以如果它是零,我会加一个,如果是一个

那么我将加零。人们说这是曼彻斯特的编码。


请注意,左手边只需接受一下每一次

操作。


如何做到这一点,谢谢。

Hi every one,

I got very basic question, here i go:

Say i have 11001 11010 bits which are infact 10 bits. Now i want to
address every bit so if it is zero i would add one and if it is one
then i would be adding zero. Folks say it manchester coding.

Please note that left hand side just accept a single bit for every
operation.

how to do this , thanks.

推荐答案

Jhon发布:
Jhon posted:
大家好,

我有一个非常基本的问题,我在这里说:

说我有11001 11010位,实际上是10位。现在我想要解决每一点所以如果它是零,我会添加一个,如果它是一个
那么我将添加零。人们说这是曼彻斯特的编码。

请注意,左手边只需要接受一个位来进行每次操作。

如何做到这一点,谢谢。
Hi every one,

I got very basic question, here i go:

Say i have 11001 11010 bits which are infact 10 bits. Now i want to
address every bit so if it is zero i would add one and if it is one
then i would be adding zero. Folks say it manchester coding.

Please note that left hand side just accept a single bit for every
operation.

how to do this , thanks.




我会帮忙,而不是为你工作。


unsigned long ManCode(unsigned long const x )

{

unsigned long result = x;


for(unsigned i = 0; i< 10; ++ i)

{

if(!GetBit(x,i))++ result;

}


返回结果;

}


-Tomás



I''ll give a hand, rather than do the work for you.

unsigned long ManCode(unsigned long const x)
{
unsigned long result = x;

for(unsigned i = 0; i < 10; ++i)
{
if ( ! GetBit(x,i) ) ++result;
}

return result;
}

-Tomás


" Jhon" < JH ********** @ gmail.com>在消息中写道

news:11 ********************** @ g43g2000cwa.googlegr oups.com ...
"Jhon" <jh**********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
大家好,

我得到了一个非常基本的问题,我在这里说:

说我有11001 11010位,实际上是10位。现在我想要解决每一点所以如果它是零,我会添加一个,如果它是一个
那么我将添加零。人们说这是曼彻斯特的编码。

请注意,左手边只需要接受一个位来进行每次操作。

如何做到这一点,谢谢。
Hi every one,

I got very basic question, here i go:

Say i have 11001 11010 bits which are infact 10 bits. Now i want to
address every bit so if it is zero i would add one and if it is one
then i would be adding zero. Folks say it manchester coding.

Please note that left hand side just accept a single bit for every
operation.

how to do this , thanks.




我不太确定你要做什么。你是想尝试1'的

赞美比特流吗?

11001 11010变为00110 00101?简单或与1.


0 | 1 = 1

1 | 1 = 0


或者你想做一些与众不同的事情吗?



I''m not quite sure what you''re trying to do. Are you trying to 1''s
compliment the bit stream?
11001 11010 becomes 00110 00101 ? Simply or the bits with 1.

0 | 1 = 1
1 | 1 = 0

Or are you trying to do something different?


有一种非常性感的方法可以做到这一点。通过屏蔽,甚至从奇数位分开

。将奇数位向右移1,因此它们与

偶数位对齐(最右边的位为0)。现在添加两个。


现在通过屏蔽(屏蔽00110011 ...和11001100 ......

)将每2位分开并将后者移动两位在右边。再次添加。


现在通过屏蔽(屏蔽00001111 ....和

11110000 ...)将每4位分开并移位4,添加。


等等(如果你只有10位,你可以停在2x 8)。非常快,

非常聪明。它实质上是并行添加各个位。不过我不是b / b
;-)

There is an extremely sexy way to do this. Separate even from odd bits
by masking. Shift odd bits to the right by 1, so they align with the
even bits (right-most bit is 0). Now add the two.

Now separate every 2 bits by masking (masks 00110011... and 11001100...
) and shift the latter by two to the right. Add again.

Now separate every 4 bits by masking (masks 00001111.... and
11110000...) and shift by 4, add.

And so on (if you have only 10 bits, you can stop at 2x 8). Very fast,
very clever. It essentially adds individual bits in parallel. It''s not
from me though;-)


这篇关于基本位操作问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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