oos-utils
oos-utils copied to clipboard
Create a num2bin function
Example is in oos_util_totp.to_binary Changes to be made:
- [ ] Expand the varchar2 from
8to something much larger - [ ] Change the input from
numbertopls_integersince we're not handling decimals - [ ] How to handle negative numbers? leading bit?
function to_binary(p_num number) return varchar2
is
l_szbin varchar2(8);
l_nrem number := p_num;
begin
if p_num = 0 then
return '0';
end if;
while l_nrem > 0 loop
l_szbin := mod(l_nrem, 2) || l_szbin;
l_nrem := trunc(l_nrem / 2 );
end loop;
return l_szbin;
end to_binary;
Duplicate of #67 ?