Re: PGSQL function for converting between arbitrary numeric bases?

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Simon Kinsella <simon(at)bluefiresystems(dot)co(dot)uk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: PGSQL function for converting between arbitrary numeric bases?
Date: 2005-08-19 14:59:35
Message-ID: 20050819145935.GB11542@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, Aug 15, 2005 at 16:48:40 +0100,
Simon Kinsella <simon(at)bluefiresystems(dot)co(dot)uk> wrote:
> Hello,
>
> I'm looking - without luck so far - for a PGSQL function for converting
> numbers between two arbitrary bases (typically base 10,16 and 26 in my
> case). Something similar to the C 'strtol' function or, ideally, PHP's
> baseconvert(string,frombase,tobase) function.
>
> I've search the docs, lists and various other forums but so far no luck.
> Just wondered if I've missed anything - all suggestions gratefully received.

I think you are looking at this wrong. You aren't really converting the
numbers. What base is used is only relevant during input and output.
You can write your own input and output functions based on the code used
for the standard input an output functions. There is already a to_hex
function that will convert an integer to text using hexadecimal notation.
For input from hex you might be able to use bit string constants
(e.g. x'10'::int).

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Halley Pacheco de Oliveira 2005-08-20 11:25:16 Re: SQL CASE Statements
Previous Message gherzig 2005-08-19 13:34:56 Re: [SOT] pypgsql function receiving dictionary as parameter?