简体   繁体   English

ushort a,ushort b从(ushort)(a | b)到常数为b的a

[英]ushort a, ushort b from ( ushort )( a | b ) to a with constant b

I am working with data that is b and in more detail is described by a. 我正在使用b数据,而a更详细地描述了该数据。 Atleast that is how i understand it. 这就是我的理解。 Any further links to basic bitwise operations are appreciated. 赞赏与基本按位操作的任何其他链接。 All objects i am looking at have b as 0x8000. 我正在查看的所有对象的b均为0x8000。 I need to find out a from c. 我需要从c中找出一个。

I have: 我有:

ushort a
ushort b

a is from 2-5 a是2-5

b = 0x8000

ushort c = (ushort)( a | b )

can i and if yes how can i come from c to a? 我可以吗,如果可以,我怎么能从c变成a?

I tried ( a & b ) but that leads me to b not a. 我尝试了(a&b),但是这导致我不是b。 I am realy stuck although i know it should be easy if possible if i would understand the operations. 我真的很固执,尽管我知道如果我能理解操作的话,应该很容易。

Basically, it's c AND NOT b . 基本上是c AND NOT b

ushort a2 = (ushort) (c & ~b);

but only because a is from 2-5 and that is smaller than 0x8000. 但这仅是因为a来自2-5 ,并且小于0x8000。
When a and b start to overlap in bits you're stranded. ab开始重叠时,您就陷入困境。

This will only work if a if smaller that b, which is true from the interval you give for a. 仅当a小于b时才有效,这从您为a给出的时间间隔开始是正确的。

Both of these will work : 这两个都将起作用:

a = (ushort) (c & ~b)  
a = (ushort) c - b

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

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