Skip to content

Create a num2bin function #128

@martindsouza

Description

@martindsouza

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;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions