pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
PGSQL function for converting between arbitrary numeric bases?
2+ messages / 2 participants
[nested] [flat]

* PGSQL function for converting between arbitrary numeric bases?
@ 2005-08-15 15:48  Simon Kinsella <simon@bluefiresystems.co.uk>
  0 siblings, 1 reply; 2+ messages in thread

From: Simon Kinsella @ 2005-08-15 15:48 UTC (permalink / raw)
  To: pgsql-sql

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.

Many thank,

Simon K





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: PGSQL function for converting between arbitrary numeric bases?
@ 2005-08-19 14:59  Bruno Wolff III <bruno@wolff.to>
  parent: Simon Kinsella <simon@bluefiresystems.co.uk>
  0 siblings, 0 replies; 2+ messages in thread

From: Bruno Wolff III @ 2005-08-19 14:59 UTC (permalink / raw)
  To: Simon Kinsella <simon@bluefiresystems.co.uk>; +Cc: pgsql-sql

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).



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-08-19 14:59 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-08-15 15:48 PGSQL function for converting between arbitrary numeric bases? Simon Kinsella <simon@bluefiresystems.co.uk>
2005-08-19 14:59 ` Bruno Wolff III <bruno@wolff.to>

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