From: Bruno Wolff III <bruno@wolff.to>
To: Simon Kinsella <simon@bluefiresystems.co.uk>
Cc: pgsql-sql@postgresql.org
Subject: Re: PGSQL function for converting between arbitrary numeric bases?
Date: Fri, 19 Aug 2005 09:59:35 -0500
Message-ID: <20050819145935.GB11542@wolff.to> (raw)
In-Reply-To: <20050815154850.11963529D9@svr1.postgresql.org>
References: <20050815154850.11963529D9@svr1.postgresql.org>
On Mon, Aug 15, 2005 at 16:48:40 +0100,
Simon Kinsella <simon@bluefiresystems.co.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).
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: bruno@wolff.to, simon@bluefiresystems.co.uk
Subject: Re: PGSQL function for converting between arbitrary numeric bases?
In-Reply-To: <20050819145935.GB11542@wolff.to>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox