Decimal to Binary

Hi,
Can we convert decimal values stored in a column to binary using select statement?
Has Oracle 10g any built-in function that supports such conversions.

and of course an example using the model clause ;-)
SQL> create table numbers
  2  as
  3  select 0 n from dual union all
  4  select 1 from dual union all
  5  select 2 from dual union all
  6  select 15 from dual union all
  7  select 16 from dual union all
  8  select 21 from dual union all
  9  select 1023 from dual union all
10  select 1024 from dual union all
11  select 3571 from dual
12  /
Tabel is aangemaakt.
SQL> select a n
  2       , to_number(b) binary
  3    from numbers
  4   model
  5         partition by (n a)
  6         dimension by (0 i)
  7         measures (n, cast(null as varchar2(4000)) b)
  8         rules iterate(20)
  9         ( b[0] = b[0] || case when n[0] >= power(2,19-iteration_number) then '1' else '0' end
10         , n[0] = n[0] - case when n[0] >= power(2,19-iteration_number) then power(2,19-iteration_number) else 0 end
11         )
12   order by n
13  /
                   N               BINARY
                   0                    0
                   1                    1
                   2                   10
                  15                 1111
                  16                10000
                  21                10101
                1023           1111111111
                1024          10000000000
                3571         110111110011
9 rijen zijn geselecteerd.Regards,
Rob.

Similar Messages

  • Hi I would like to know if you can convert decimal to binary using actionscript 3.0?

    Hi I would like to know if you can convert decimal to binary using actionscript 3.0?

    Hi thanks for the response Ive tried to implement the code as you stated but it is not outputting please if you could check the following code and let me know where Ive gone wrong that would be much appreciated Thanks!.
    miles_txt.addEventListener(KeyboardEvent.KEY_DOWN,convertKilometres);
    miles_txt.restrict ="0-9";
    function convertKilometres (k:KeyboardEvent):void {
    var miles:Number;
    var kilometres:Number;
    if (k.keyCode == Keyboard.ENTER){
    miles=Number(miles_txt.text);
    kilometres=miles* 1.609344;
    kilometres_txt.text = kilometres.toPrecision(2);
    kilometreConvert_txt.addEventListener(KeyboardEvent.KEY_DOWN,convertKiloToMile);
    kilometreConvert_txt.restrict = "0-9";
    function convertKiloToMile(k:KeyboardEvent):void{
    var kilometreConvert:Number;
    var milesAnswer:Number;
    if (k.keyCode==Keyboard.ENTER) {
    kilometreConvert=Number(kilometreConvert_txt.text);
    milesAnswer=kilometreConvert* 0.621371192;
    milesAnswer_txt.text = milesAnswer.toPrecision(2);
    binary_txt.addEventListener(KeyboardEvent.KEY_DOWN, checkEnterKey2);
    function checkEnterKey2(e:KeyboardEvent):void{
    if(binary_txt.text != '' && e.keyCode == Keyboard.ENTER){
    decimal_txt.text=binaryToDecimal(binary_txt.text).toString();
    function binaryToDecimal(s:String):Number{
    var n:Number = 0
    for(var i:int=0;i<s.length;i++){
    n+=Number(s.substr(i,1))<<(s.length-1-i)
    return n;
    function decimalToBinary(n:Number):String{
    return n.toString(2);
    return_btn.addEventListener(MouseEvent.CLICK, goBackToCalculator);
    function goBackToCalculator(e:Event):void
    mybuttonSound.play();
    gotoAndStop("Calculator");
    clear_btn.addEventListener(MouseEvent.CLICK,clearField);
    function clearField(e:MouseEvent):void{
      mybuttonSound.play();
      miles_txt.text ="";
      kilometres_txt.text ="";
      milesAnswer_txt.text ="";
      kilometreConvert_txt.text ="";
      binary_txt.text ="";
      decimal_txt.text ="";

  • Decimal to binary conversion

    hi...anyone here knows the code to convert decimal to binary.Please help me!!!

    Here's the answer in a riddle - to fill in the blank line is to understand the algorithm used - have fun!
    class BinaryConverter{
       public static void main(String []args) throws Error{
          try{
             new BinaryConverter(Integer.parseInt(args[0]));
          }catch(ArrayIndexOutOfBoundsException e){
             System.out.println("No argument entered");
          } catch(NumberFormatException e){
             System.out.println("Enter whole numbers only");
       private BinaryConverter(int i){
          System.out.println("The binary number is: ");          
          convert(i, 0, (long)Math.pow(2, 31));
       private void convert(int num, int i, long max){
          if(num / max==1) System.out.print("1");
          else System.out.print("0");
          num %= max;
          // there is a line deliberately removed here!
          if(i++ % 8 ==0) System.out.print(" ");
          if(max >0) convert(num, i, max);
    }

  • Do anyone know how to convert a decimal to binary, 1 into 01

    do anyone know how to convert a decimal to binary
    i wants to convert 1 into 01, but the computer print out 1, it didn't print 0
    also 0 it also print only 0, and 3 it print11
    so decimal of 3, the computer print correct, but 0 and 1 it print wrong
    how can i print 01 if my decimal is 1
    int a=1;
    System.out.print(Integer.toBinaryString(a));
    can anyone help me solve this question
    and
    you can use java or jsp
    if you can use jsp it would be better, if not use java

    it's not printing anything 'wrong'.
    0 in binary is 0
    1 in binary is 1
    All it's doing is cutting off leading zeros since they don't change the value.
    1 is the same as 01 is the same as 00000001...no difference
    Similarly, when you print decimal 3 as 11, it could just as easily say 00000011 and be correct, since the zeros don't change anything.

  • Conversion of Decimal to Binary String

    Hello Labview People:
    I'm rather new to Labview, so this may be a simple-minded question . . .
    I would like to take a numeric control and have the decimal input
    converted to a binary string of 8 bits. So, for example, if I were to
    put in the number '127', I would get out (on an indicator) the string:
    01111111
    The number '128' would show on the indicator as:
    10000000
    It seems to me that this should be simple, but somehow I cannot figure
    out how to do it. Must an array be built bit by bit to accomplish this?
    (I'm afraid I don't yet know how to build arrays.)
    Thanks in advance for any help you provide!
    Sent via Deja.com http://www.deja.com/
    Before you buy.

    Or, you can go under the numeric function, and look for conversions, get
    decimal to byte array conversion.
    Then what you need to do is to get an array selection vi, and index to zero.
    I don't remember the exact name of the VI's because I don't have LabView
    here with me.
    Perhaps this complicates things
    Steven
    "Timo Miettunen" wrote in message
    news:[email protected]..
    > use format into string VI from string palette
    >
    > format string should be "%08b" for 8 bits, "%016b" for 16 bits etc.
    >
    > timo
    >
    > Ananda Dave wrote:
    > >
    > > Hello Labview People:
    > >
    > > I'm rather new to Labview, so this may be a simple-minded question . . .
    > >
    > > I would like to take a numeric control and have the decimal input
    > >
    converted to a binary string of 8 bits. So, for example, if I were to
    > > put in the number '127', I would get out (on an indicator) the string:
    > >
    > > 01111111
    > >
    > > The number '128' would show on the indicator as:
    > >
    > > 10000000
    > >
    > > It seems to me that this should be simple, but somehow I cannot figure
    > > out how to do it. Must an array be built bit by bit to accomplish this?
    > > (I'm afraid I don't yet know how to build arrays.)
    > >
    > > Thanks in advance for any help you provide!
    > >
    > > Sent via Deja.com http://www.deja.com/
    > > Before you buy.
    >
    > --
    > -------------------------------------------------
    > Timo Miettunen
    >
    > Fincitec Oy Production Department
    > e-mail: [email protected]
    > Address:
    > Lumikontie 2 Tel: +358-16-2151245
    > PO BOX 11 Fax: +358-16-221561
    > FIN-94600 KEMI Finland
    > -------------------------------------------------

  • Converting from decimal to binary to hexadecimal to octal

    hello everyone,
    my question is, Is there a way to get decimal input from user and print the binary, hexadecimal and octal value of that decimal? just like C does in printf command

    http://java.sun.com/j2se/1.3/docs/api/java/lang/Integer.html

  • Convert decimal to binary

    hi all!
    I want to convert from message box witch is in ascii (decimal) to a signal in binary... can anyone help me?
    thanks in advance

    hello,
    I've made this example. It's strange. But in the moment it's my only idea.
    it output's two different ways. Because I didn't understand exactly what you need.
    Software developer
    www.mcm-electronics.com
    PS: Don't forget to rate a good anwser ; )
    Currently using Labview 2011
    PORTUGAL
    Attachments:
    Convert.vi ‏10 KB

  • Convert decimal to binary with a fixed length

    Hi, I need to write a program that converts a decimal number to binary with a fixed length (say 5), for example, decimal digit "0" -> binary number "00000". I try Integer.toBinaryString(), but it will just cut off the leading bits, so I wonder how to let the conversion happen, anyone can help me with that, thanks in advance.
    mckie

    Daiyue_Weng wrote:
    Hi, I need to write a program that converts a decimal number to binary with a fixed length (say 5), for example, decimal digit "0" -> binary number "00000". I try Integer.toBinaryString(), but it will just cut off the leading bits, so I wonder how to let the conversion happen, anyone can help me with that, thanks in advance.
    mckieWhat do you expect it to do? When you limit yourself to 5 digits binary you can only represent 0 to 63 and you will loose anything not in those 5 digits.

  • Decimal to binary conversion script

    hi
    i m very happy to all of u on ur response
    i m really happy with this forum
    i need a script to convert the decimal number in to binary
    number
    83---------->1010011
    thx

    here are two handlers I picked up from James Newton. I
    couldn't find them anywhere on his site (
    http://nonlinear.openspark.com)
    so I paste them directly here.
    credits go to James.
    on mMakeRuleMap(anInteger)
    -- INPUT: <anInteger> must be an integer
    -- OUTPUT: Returns a 32-item list of 0s and 1s corresponding
    to the
    -- binary representation of anInteger
    if anInteger < 0 then
    tBinary = mMakeRuleMap(the maxInteger + 1 + anInteger)
    tBinary[1] = 1
    else
    tBinary = []
    tBits = 32
    tBinary[32] = 0
    repeat while anInteger
    tBinary[tBits] = anInteger mod 2
    anInteger = anInteger / 2
    tBits = tBits - 1
    end repeat
    end if
    return tBinary
    end mMakeRuleMap
    on mBinaryToDecimal(aBitList)
    -- INPUT: <aBitList> is a list of 0s and 1s (up to 32
    items)
    -- OUTPUT: a decimal number corresponding to the binary
    number
    -- defined by <aBitList>
    tBitValue = 1
    tDecimal = 0
    i = aBitList.count
    if i = 32 then
    if aBitList[1] = 1 then
    -- The number is negative
    i = 31
    tDecimal = the maxInteger + 1
    end if
    end if
    repeat while i
    if aBitList
    then
    tDecimal = tDecimal + tBitValue
    end if
    tBitValue = tBitValue * 2
    i = i - 1
    end repeat
    return tDecimal
    end mBinaryToDecimal

  • Cobol Packed Decimal and Binary Compressed Numbers

    Hello!
    I am having some difficulties finding the correct datatype in Oracle for numbers in flat files coming from Cobol which are packed-decimal type and binary compressed. These are not objects, hence the use of BLOB is not appropriate?!
    Thaks for any help!!!
    null

    The sqlloader manual (i.e. utilities reference, loader chapters) tells all about how to load packaed decimal.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Adrian Zeller ([email protected]):
    Hello!
    I am having some difficulties finding the correct datatype in Oracle for numbers in flat files coming from Cobol which are packed-decimal type and binary compressed. These are not objects, hence the use of BLOB is not appropriate?!
    Thaks for any help!!!<HR></BLOCKQUOTE>
    null

  • Convert decimal to binary values

    Hello friends, I have this:
    Doblue [ ][ ] dbValues;and I need convert that array in a binary values...and save it in a File
    Do you know how can I do it?....thanks

    So, I need create a binary file, how can I creat
    it??..thanks....There. Are. No. Files. That. Are. Not. Binary.
    File f = new File("/wherever/whatever.name");
    FileOutputStream fos = new FileOutputStream(f);Wrap an ObjectOutputStream around fos and stuff in the array. Like I already said.

  • Conversion from decimal to binary!

    int i=1234;How can I convert an integer to its binary form??

    int i = 1234;
    String binInt = Integer.toBinaryString(i);

  • How to convert decimal to binary

    example:
    source:254254254254
    target:11111110111111101111111011111110

    With the following you can convert a long type value to a binary String with leading zeros. If you would not like leading zeros you can modify it in a trivial way.
      final static char[] coeffs = new char[]{(char)0x30,(char)0x31};
    public static String toBinary(long n) {
      char[] binary = new char[64];
      for(int j=0;j<binary.length;j++) binary[j]=(char)0x30; // If leading zeros are not required, simply omit this line.
      int charPointer = binary.length-1; 
      if(n==0L) return "0";
      while (n!=0L){
          binary[charPointer--] = coeffs[(int)n&1];
          n >>>= 1;
    return new String(binary);
    }

  • Binary to decimal, including negatives

    HI i have been searching through the forums but have been unable to find how to do this.
    I am using a 12bit word and need to convert it to decimal. I have tried using the Integer.parseInt(b, 2) method, however i cannot seam to make this work for negative numbers. I am using the two's compliment method to store negative numbers, for example -3 becomes 111111111100.
    Thanks for any help that you can give me!
    Alex

    The reason i'm using a 12 bit word is that the program is a simulator for the first minicomputer the DEC PDP-8. What i have to make you see is a machine code simulator, that reads in decimal values from a text file then converts these to binary and uses them as machine code.
    There seams to be an awefull lot of decimal to binary and visa versa conversion in this as when i perform a simple add the easiest way i have found is to convert both numbers to dec then add then convert back to binary.
    Thanks for all the help your giving me i still havn't managed to make it work yet though!
    Alex

  • About binary number and decimal number?

    how to use a class to convert a decimal number from a binary number?Thank you

    You've already asked the same kind of thing before (http://forum.java.sun.com/thread.jsp?forum=31&thread=325249), and fsato4 answered. Here is the same thing, but decimal to binary.
    public class ToBinary {
         public static void main(String[] args) {
              int n = 12; 
              System.out.println(Integer.toString(n)); 
              System.out.println(Integer.toBinaryString(n));

Maybe you are looking for

  • Functions in a class

    Ok, I have found defining classes in .as files can be very useful for me. I have a few functions that are being called over and over again in different movies. There is what I want / need to do in order to stream line the creating and updating of the

  • Firefox is stuck on "new tab"

    I can open my Firefox by my desktop shortcut and open as many "new tab" pages as I would like. The problem is I can't go to any other pages. No urls will work, I can type them in but as soon as I hit enter it just returns to the blank "new tab" page.

  • How to Restore Safari Bookmarks with Time Machine in Lion

    Hi - I want to restore my Safari bookmarks. I am running Lion and have a Time Machine backup with the correct bookmarks.plist file. The problem - as I see it - is that the "Library" folder - where the Safari bookmarks.plist file is located - no longe

  • Oracle 10g multi node installation

    Hi, Multi node installation for Oracle 10g Appl Server - Node A: Install core business Database server. - Node B: Install Application Server Infrastructure (OID, repository database). - Node C: Install Application server middle tier (forms, reports,

  • About loops,conditions

    Hello @ll,     I am new to ABAP and I got a task to modify functionality of an Include.There are somany loops and if,case etc., conditions in it ....My Question is how to check the code its almost around 1500 lines code...How to check the each loop a