oos-utils icon indicating copy to clipboard operation
oos-utils copied to clipboard

Create a num2bin function

Open martindsouza opened this issue 9 years ago • 1 comments

Example is in oos_util_totp.to_binary Changes to be made:

  • [ ] Expand the varchar2 from 8 to something much larger
  • [ ] Change the input from number to pls_integer since 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;

martindsouza avatar Oct 09 '16 03:10 martindsouza

Duplicate of #67 ?

zhudock avatar Jun 28 '17 20:06 zhudock