仅从OR和AND进行XOR [英] XOR from only OR and AND

查看:69
本文介绍了仅从OR和AND进行XOR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果只有AND和OR运算,如何进行XOR按位运算?

How do you do the XOR bitwise operation if you only have available the AND and the OR operations?

推荐答案

创建我自己的脚本语言-ChrisScript-您只需要以下内容:

Creating my own scripting language - ChrisScript - you just need something like:

#!/bin/chrish

bit XOR (bit A, bit B)
{
   bit notA;
   bit notB;

   IF (A == 0) notA = 1 ELSE notA = 0;
   IF (B == 0) notB = 1 ELSE notB = 0;

   F = ((A && notB) || (notA && B));

   RETURN F;
}

即使没有NOT,也可以这样模拟.但是,这是在没有某种形式的逆变器的情况下获得的最佳解决方案.我很难相信您没有某种形式的逆变器-您正在使用什么脚本环境?

Even without NOT, it can be emulated like this. But this is the best solution you're going to get without having some form of inverter. I find it hard to believe you don't have some form of inverter availble -- what scripting environment are you using?

这篇关于仅从OR和AND进行XOR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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