Oracle按位运算符
来源:互联网 发布:手机变砖刷机软件 编辑:程序博客网 时间:2024/05/18 01:49
利用bitand实现多种位操作
转:http://www.oracle.com.cn/viewthread.php?tid=83181
ORACLE中为什么只有BITAND而没有BITOR, BITXOR,原因是,有了BITAND,
很容易实现BITOR和BITXOR.BITOR(x,y) = (x + y) - BITAND(x, y);
BITXOR(x,y) = BITOR(x,y) - BITAND(x,y) = (x + y) - BITAND(x, y) * 2;
实现了位操作| ,^, &, <<, >> ,取一个整数某位的值,为了简明起见,大部分没有判断参数合法性,效率和系统bitand在一个数量级
请各位检查是否有其他错误
create or replace function bitor0(x IN NUMBER,y IN NUMBER)
return number is
n_result number;
begin
n_result:=(x + y) - BITAND(x, y);
return n_result;
end;
/
create or replace function bitor(x IN NUMBER,y IN NUMBER)
return number is
begin
return (x + y) - BITAND(x, y);
end;
/
create or replace function bitxor0(x IN NUMBER,y IN NUMBER) --faster
return number is
begin
return (x + y) - BITAND(x, y)*2;
end;
/
create or replace function bitxor(x IN NUMBER,y IN NUMBER) --slower
return number is
begin
return (x + y) - BITAND(x, y)- BITAND(x, y);
end;
/
create or replace function bitxor(x IN NUMBER,y IN NUMBER) --fast
return number is
n_result number;
begin
n_result:= BITAND(x, y);
return (x + y) - n_result- n_result;
end;
/
create or replace function bitnot(x IN NUMBER) --~x=x^0xffff
return number is
n_result number;
begin
n_result:= BITAND(x, -1);
return (x -1 ) - n_result- n_result;
end;
/
create or replace function bitlmv(x IN NUMBER,y IN NUMBER)
return number is
begin
return x* power(2,y);
end;
/
create or replace function bitrmv(x IN NUMBER,y IN NUMBER)
return number is
begin
return trunc(x/ power(2,y));
end;
/
create or replace function bitget(x IN NUMBER,y IN NUMBER)
return number is
n_result number;
begin
n_result :=power(2,y-1);
return bitand(x,n_result)/n_result;
end;
/
create or replace function bitgeta(x IN NUMBER,y IN NUMBER)
return number is
n_result number;
begin
n_result :=power(2,y-1);
if bitand(x,n_result)>0 then
return 1;
else
return 0;
end if;
end;
/
ORACLE中为什么只有BITAND而没有BITOR, BITXOR,原因是,有了BITAND,
很容易实现BITOR和BITXOR.BITOR(x,y) = (x + y) - BITAND(x, y);
BITXOR(x,y) = BITOR(x,y) - BITAND(x,y) = (x + y) - BITAND(x, y) * 2;
实现了位操作| ,^, &, <<, >> ,取一个整数某位的值,为了简明起见,大部分没有判断参数合法性,效率和系统bitand在一个数量级
请各位检查是否有其他错误
create or replace function bitor0(x IN NUMBER,y IN NUMBER)
return number is
n_result number;
begin
n_result:=(x + y) - BITAND(x, y);
return n_result;
end;
/
create or replace function bitor(x IN NUMBER,y IN NUMBER)
return number is
begin
return (x + y) - BITAND(x, y);
end;
/
create or replace function bitxor0(x IN NUMBER,y IN NUMBER) --faster
return number is
begin
return (x + y) - BITAND(x, y)*2;
end;
/
create or replace function bitxor(x IN NUMBER,y IN NUMBER) --slower
return number is
begin
return (x + y) - BITAND(x, y)- BITAND(x, y);
end;
/
create or replace function bitxor(x IN NUMBER,y IN NUMBER) --fast
return number is
n_result number;
begin
n_result:= BITAND(x, y);
return (x + y) - n_result- n_result;
end;
/
create or replace function bitnot(x IN NUMBER) --~x=x^0xffff
return number is
n_result number;
begin
n_result:= BITAND(x, -1);
return (x -1 ) - n_result- n_result;
end;
/
create or replace function bitlmv(x IN NUMBER,y IN NUMBER)
return number is
begin
return x* power(2,y);
end;
/
create or replace function bitrmv(x IN NUMBER,y IN NUMBER)
return number is
begin
return trunc(x/ power(2,y));
end;
/
create or replace function bitget(x IN NUMBER,y IN NUMBER)
return number is
n_result number;
begin
n_result :=power(2,y-1);
return bitand(x,n_result)/n_result;
end;
/
create or replace function bitgeta(x IN NUMBER,y IN NUMBER)
return number is
n_result number;
begin
n_result :=power(2,y-1);
if bitand(x,n_result)>0 then
return 1;
else
return 0;
end if;
end;
/
- Oracle按位运算符
- 按位运算符
- 按位运算符
- 按位运算符
- 按位运算符
- 按位运算符& | ~ ^ >> <<
- 按位运算符
- 按位运算符
- oracle的位运算
- oracle位运算
- oracle 位运算
- Objective-C位运算符-按位与运算符
- Objective-C位运算符-按位或运算符
- 按位与运算符
- 按位与运算符&
- 按位与运算符
- C++按位运算符
- 按位“或”运算符 (|)
- 库函数调用和系统功能调用/文件句柄和文件指针/指针和引用/C runtime lib和虚拟机
- PowerDesigner 需求分析模型RQM入门
- jQuery对Selec,radio,checkbox的相关操作
- PowerDNS - Realtime Update 的 DNS 伺服器介紹
- web.config的加密和解密
- Oracle按位运算符
- ZPPR31
- 左手坐标系和右手坐标系
- 如何发布一个ASP.NET网站
- BSS段、数据段、代码段、堆与栈
- flex的number formatter示例
- 归并算法
- configure: error: No curses/termcap library found
- 再谈typedef(重点为函数指针)