Good afternoon,
I have seen on this list some time ago PL/SQL to convert a number to/from
decimal and hex.
Does anyone have PL/SQL to convert a number to/from a binary representation?
TIA,
Steven Haas
Opus Consultants, LLC
"Opinions expressed, right or wrong, are my own."
--
Please see the o
n Behalf Of Steve Haas
> Sent: Thursday, June 14, 2001 4:02 PM
> To: Multiple recipients of list ORACLE-L
> Subject: number to binary conversion
>
>
> Good afternoon,
>
> I have seen on this list some time ago PL/SQL to convert a number to/from
> decimal and hex.
> D
Here is my modification of Tom's Kyte code:
FUNCTION to_base( p_dec in number, p_base in number )
return varchar2
is
l_str varchar2(255) default NULL;
l_num number default p_dec;
l_hex varchar2(16) default '0123456789ABCDEF';
begin
if ( trunc(p_dec) <> p_dec ) then
raise PROGRAM_ERROR;
end if
Simple one attached...Handles up to 32bits, and I
could squeeze about 3000 conversions per second out of
my laptop with it.
Cheers
Connor
create or replace
package conv is
function to_binary(p_in number) return varchar2;
function from_binary(p_in varchar2) return number;
end;
/
create or re