Here is my own LPAD/RPAD solution.
I take Tom Kyte package as base and expand it.
create or replace function bin_shift_right
( p_bin in varchar2,
p_shift in number default null) return varchar2
is
l_len number;
l_shift number;
begin
l_shift := nvl(p_shift, 1);
l_len := length(p_bin);
if (l_len <= 0) then
return null;
end if;
if (l_shift > l_len) then
l_shift := l_len;
end if;
return lpad(substr(p_bin, 1, l_len - l_shift), l_len, '0');
end bin_shift_right;
create or replace function shright
( p_num in number,
p_shift in number default null) return number
is
begin
if (trunc(p_num) <> p_num OR p_num < 0) then
raise PROGRAM_ERROR;
end if;
return nvl(to_dec(bin_shift_right(to_bin(p_num), p_shift), 2), 0);
end shright;
/
And tests
SQL>
SQL> select shright(123) from dual;
SHRIGHT(123)
------------
61
SQL>
SQL> select shright(123, 2) from dual;
SHRIGHT(123,2)
--------------
30
SQL>
SQL> select shright(123, 10) from dual;
SHRIGHT(123,10)
---------------
SQL> /