Home » SQL & PL/SQL » SQL & PL/SQL » how to convert number into binary format. (oracle 10g)
how to convert number into binary format. [message #443391] Mon, 15 February 2010 08:22 Go to next message
chaituu
Messages: 115
Registered: June 2008
Senior Member
how to convert number into binary format.

for example if i give value 4 it should convert into binary representation =100
3=011
7=111
8=1000
64=100000000

any build in functions are there in oracle?


EDIT by VK: Removed code tags.

[Updated on: Mon, 15 February 2010 08:32] by Moderator

Report message to a moderator

Re: how to convert number into binary format. [message #443392 is a reply to message #443391] Mon, 15 February 2010 08:27 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please STOP putting code tags to your post, put it ONLY on code or when alignement is necessary.

There is no built-in function, but is easy to create one.

Regards
Michel
Re: how to convert number into binary format. [message #443394 is a reply to message #443392] Mon, 15 February 2010 08:31 Go to previous messageGo to next message
chaituu
Messages: 115
Registered: June 2008
Senior Member
Thanks for thr reply.i have created one.
Re: how to convert number into binary format. [message #443395 is a reply to message #443394] Mon, 15 February 2010 08:38 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Good! Could you post it.

Regards
Michel
Re: how to convert number into binary format. [message #443397 is a reply to message #443395] Mon, 15 February 2010 08:42 Go to previous messageGo to next message
chaituu
Messages: 115
Registered: June 2008
Senior Member
SELECT 
  DECODE(BITAND(VALUE, 128), 128, '1', '0') ||
  DECODE(BITAND(VALUE, 64), 64, '1', '0') ||
  DECODE(BITAND(VALUE, 32), 32, '1', '0') ||
  DECODE(BITAND(VALUE, 16), 16, '1', '0') ||
  DECODE(BITAND(VALUE, 8), 8, '1', '0') ||
  DECODE(BITAND(VALUE, 4), 4, '1', '0') ||
  DECODE(BITAND(VALUE, 2), 2, '1', '0') ||
  DECODE(BITAND(VALUE, 1), 1, '1', '0') as bin_number from 
(select 8 as value from dual) A;
Re: how to convert number into binary format. [message #443400 is a reply to message #443397] Mon, 15 February 2010 08:47 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Thanks.

I think we already addressed this point some time in the last 3 years but could not find the topic.

Michel
Re: how to convert number into binary format. [message #443403 is a reply to message #443400] Mon, 15 February 2010 08:52 Go to previous messageGo to next message
chaituu
Messages: 115
Registered: June 2008
Senior Member
Michel,

i have one personnel doubt.for every question we post here you will give reply first.i believe not only for my post i think for all other posts you will first reply.how is it possible?will you not sleep? Smile
Re: how to convert number into binary format. [message #443410 is a reply to message #443403] Mon, 15 February 2010 09:43 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://www.psoug.org/snippet/Convert_between_Decimal_Binary_Octal_and_Hex_536.htm
Re: how to convert number into binary format. [message #443411 is a reply to message #443410] Mon, 15 February 2010 09:50 Go to previous messageGo to next message
ThomasG
Messages: 3211
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
The decimal / hexadecimal conversion is already build into to_char / to_number, too.

SQL> SELECT To_Char(255,'XXXXX') FROM dual;

TO_CH
-----
   FF

SQL>
SQL>
SQL> SELECT To_Number('FF','XXXXX') FROM dual;

TO_NUMBER('FF','XXXXX')
-----------------------
                    255


Re: how to convert number into binary format. [message #443413 is a reply to message #443397] Mon, 15 February 2010 09:59 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://www.orafaq.com/scripts/plsql/numsys.txt
Re: how to convert number into binary format. [message #443414 is a reply to message #443413] Mon, 15 February 2010 10:03 Go to previous message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
I was pretty sure it existed here. Smile

Regards
Michel
Previous Topic: calling a procedure based on a distinct resultset
Next Topic: Using UTL_HTTP, are you able to send attachments in a web service?
Goto Forum:
  


Current Time: Fri Apr 26 19:21:46 CDT 2024