Oracle 中的按位异或
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/604598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bitwise exclusive OR in Oracle
提问by Schotime
In SQL ServerI have been using the ^
symbol, however that doesn't seem to work in Oracle.
在SQL Server 中,我一直在使用该^
符号,但这在Oracle 中似乎不起作用。
How do I do a bitwise exclusive OR
in Oracle?
我如何OR
在 Oracle 中进行按位排他?
回答by MarkusQ
From the docs:
从文档:
function bitor(p1 number, p2 number) return number is
begin
return p1-bitand(p1,p2)+p2;
end;
function bitxor(p1 number, p2 number) return number is
begin
return bitor(p1,p2)-bitand(p1,p2);
end;
To see that these work, follow the logic with just 0s and 1s for input, and then not that there are no borrow or caries.
要查看这些工作,请遵循只有 0 和 1 用于输入的逻辑,而不是没有借用或龋齿。
-- MarkusQ
——马库斯Q
回答by Mitch Wheat
There is the BITAND operator:
有 BITAND 运算符:
select bitand(49,54)+0 from dual;
You can build up the other operatorsfrom it.
您可以从中构建其他运算符。
回答by Quassnoi
There's no easy way.
没有简单的方法。
You may cast string HEX
values into RAW
values and use UTL_RAW
:
您可以将字符串HEX
值转换为RAW
值并使用UTL_RAW
:
SELECT UTL_RAW.bit_xor(HEXTORAW(TO_CHAR(1, 'FMX')), HEXTORAW(TO_CHAR(2, 'FMX')))
FROM dual
---
03