Excel 中的位数组 AND?
我有一个像这样的网格:
A A A A A
B C C C C C
B C C C C C
B C C C C C
B C C C C C
B C C C C C
每个 A
和 B
都是从工作表中其他地方正在进行的其他工作创建位数组而派生的数值。
在 C
中,我需要对相交的 A
和 B
执行按位 AND 并测试结果是否大于零(即,有至少有一个匹配位值为“1”)。
此必须是纯 Excel 公式,不能使用宏 - 它以条件格式使用。使用宏来模拟条件格式不是一种选择,也不能创建一个复制 C
的表并使用宏来存储条件格式可以查看的答案。
如果某些字符串魔术更容易执行,则 A
和 B
的值可以存储为包含 1 和 0 的字符串。
有什么想法吗?
编辑
接受的答案给了我我需要的东西,但对于后代,以下是如何扩展它以扩展该解决方案以返回按位答案:
AND = SUBSTITUTE(SUBSTITUTE(TEXT(VALUE($A2)+VALUE(B$1),"1","0"),"2","1")
OR = SUBSTITUTE(TEXT(VALUE($A2)+VALUE(B$1),"2","1")
XOR = SUBSTITUTE(TEXT(VALUE($A2)+VALUE(B$1),"2","0")
I have a grid something like this:
A A A A A
B C C C C C
B C C C C C
B C C C C C
B C C C C C
B C C C C C
Each A
and B
are numeric values derived from creating a bit array from some other work going on elsewhere in the worksheets.
In C
, I need to perform a bitwise AND on the intersecting A
and B
and test if the result is greater than zero (i.e., there's at least one matching bit value of "1").
This must be a pure Excel formula, can't use macros--it is used in a conditional format. Using macros to simulate conditional formatting is not an option, nor is creating a table that duplicates C
and uses a macro to store the answer that the conditional formatting can look at.
The values for A
and B
could be stored as a string with 1's and 0's if some string magic is easier to perform.
Any ideas?
edit
The accepted answer gives me what I need, but for posterity, here's how to extend it to extend that solution to give bitwise answers back:
AND = SUBSTITUTE(SUBSTITUTE(TEXT(VALUE($A2)+VALUE(B$1),"1","0"),"2","1")
OR = SUBSTITUTE(TEXT(VALUE($A2)+VALUE(B$1),"2","1")
XOR = SUBSTITUTE(TEXT(VALUE($A2)+VALUE(B$1),"2","0")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其另存为 0 和 1 的字符串,将它们作为数字相加,将其转换为字符串,然后
在单元格 B2 中查找 A2 和 B1 中的数据,然后复制并粘贴。
编辑:哇!他们放入了一个函数 DEC2BIN()!
并给他们留下号码。
save it as a string of 0 and 1, add them as numbers together, convert that to string and look for a 2.
copy in cell B2 with data in A2 and B1, then copy&paste around.
edit: Wow! they have put in a function DEC2BIN()!
and leave them numbers.
=(A + B) > 怎么样? 0
如果您正在执行 OR (您正在描述的)或=(A + B) > 1
如果你正在做AND(就像你实际上在写一样)。What about
=(A + B) > 0
if you're doing OR (which you're describing) or=(A + B) > 1
if you're doing AND (like you're actually writing).