Skip to main content
Tweeted twitter.com/StackDBAs/status/1137962827505983488
Became Hot Network Question
deleted 71 characters in body; deleted 1 character in body; edited title; deleted 1 character in body
Source Link
Colin 't Hart
  • 9.4k
  • 15
  • 36
  • 44

PL/SQL function to receive a number and return it'sits binary format

Hope you're doing well. I'm new to PL/SQL and I'm trying to write a function to receive a number and return it'sits binary format  . This is what I've developed so far and it's ok for inputs : 4,8,16 but it does not return correct binary format for other numbers. I could not find the problem and I was wondering if you could find the problem . thanks in advance.?

create or replace function Show_Binary(i_Number in Number) Return Varchar2 
  AS

     V_Binary varchar2(50) := '';
     i_Number2 Number := i_Number;
       Begin
         While i_Number2>=2 LOOP

          V_Binary := V_Binary || Remainder(i_Number2, 2);
          i_Number2 := i_Number2 / 2;

       End LOOP;
          V_Binary := V_Binary || TO_CHAR(i_Number2);
          select reverse (V_Binary) into V_Binary from dual;
      return (V_Binary);
   End;

PL/SQL function to receive a number and return it's binary format

Hope you're doing well. I'm new to PL/SQL and I'm trying to write a function to receive a number and return it's binary format  . This is what I've developed so far and it's ok for inputs : 4,8,16 but it does not return correct binary format for other numbers. I could not find the problem and I was wondering if you could find the problem . thanks in advance.

create or replace function Show_Binary(i_Number in Number) Return Varchar2 
  AS

     V_Binary varchar2(50) := '';
     i_Number2 Number := i_Number;
       Begin
         While i_Number2>=2 LOOP

          V_Binary := V_Binary || Remainder(i_Number2, 2);
          i_Number2 := i_Number2 / 2;

       End LOOP;
          V_Binary := V_Binary || TO_CHAR(i_Number2);
          select reverse (V_Binary) into V_Binary from dual;
      return (V_Binary);
   End;

PL/SQL function to receive a number and return its binary format

I'm trying to write a function to receive a number and return its binary format. This is what I've developed so far and it's ok for inputs : 4,8,16 but it does not return correct binary format for other numbers. I could not find the problem and I was wondering if you could find the problem?

create or replace function Show_Binary(i_Number in Number) Return Varchar2 
  AS

     V_Binary varchar2(50) := '';
     i_Number2 Number := i_Number;
       Begin
         While i_Number2>=2 LOOP

          V_Binary := V_Binary || Remainder(i_Number2, 2);
          i_Number2 := i_Number2 / 2;

       End LOOP;
          V_Binary := V_Binary || TO_CHAR(i_Number2);
          select reverse (V_Binary) into V_Binary from dual;
      return (V_Binary);
   End;
Source Link
Pantea
  • 1.5k
  • 5
  • 28
  • 58

PL/SQL function to receive a number and return it's binary format

Hope you're doing well. I'm new to PL/SQL and I'm trying to write a function to receive a number and return it's binary format . This is what I've developed so far and it's ok for inputs : 4,8,16 but it does not return correct binary format for other numbers. I could not find the problem and I was wondering if you could find the problem . thanks in advance.

create or replace function Show_Binary(i_Number in Number) Return Varchar2 
  AS

     V_Binary varchar2(50) := '';
     i_Number2 Number := i_Number;
       Begin
         While i_Number2>=2 LOOP

          V_Binary := V_Binary || Remainder(i_Number2, 2);
          i_Number2 := i_Number2 / 2;

       End LOOP;
          V_Binary := V_Binary || TO_CHAR(i_Number2);
          select reverse (V_Binary) into V_Binary from dual;
      return (V_Binary);
   End;