[GENERAL] Is there a function for Converting a Decimal into BINARY ?

2009-08-27 Thread Ow Mun Heng
Hi Guys,

Searching the net didn't give me much clues as to how to convert a Decimal
number into BINARY.


Eg:
I have a datatype in the DB which needs to be converted.

DEC = 192
BINARY = 1100

DEC = 197
BINARY = 11000101

Which I then need to break down into pairs to do calculations on

11 : 00 : 00 : 00
11 : 00 : 01 : 01

Some of the solutions I've seen on the Internet is based on VB and mainly
userland apps, I would like to do the conversion within PG itself.

Thanks

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Is there a function for Converting a Decimal into BINARY ?

2009-08-27 Thread John R Pierce

Ow Mun Heng wrote:

Hi Guys,

Searching the net didn't give me much clues as to how to convert a Decimal
number into BINARY.
  


well, a decimal number is a fixed point number stored in a modified BCD 
format, which optionally can contain a decimal fractional component.


you likely would want to convert it to a INTEGER or BIGINT first,  then 
cats it to BIT(n) where N is the number of bits you want.


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Is there a function for Converting a Decimal into BINARY ?

2009-08-27 Thread Harvey, Allan AC
 Eg:
 I have a datatype in the DB which needs to be converted.
 
 DEC = 192
 BINARY = 1100

How about this

gwmdb= select 192::bit(16);
   bit
--
 1100
(1 row)

Hope that helps

Allan


The material contained in this email may be confidential, privileged or 
copyrighted. If you are not the intended recipient, use, disclosure or copying 
of this information is prohibited. If you have received this document in error, 
please advise the sender and delete the document. Neither OneSteel nor the 
sender accept responsibility for any viruses contained in this email or any 
attachments.

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general