Program to convert binary to decimal number?

I only know how to do a program that converts only 4 numbers, but it to convert any amount of digits the number enters, I think you need to use a loop or something, but I'm not sure how. Could someone please help me? This is my code so far:
import javax.swing.JOptionPane;
public class bintodec {
     public static void main (String[] args) {
          String input;
          int number,digit1,digit2,digit3,digit4,result;
          input = JOptionPane.showInputDialog ("Enter a binary number.");
          number = Integer.parseInt(input);
          digit1 = ((number % 10000) - (number % 10000 % 1000)) / 1000;
          digit2 = ((number % 1000) - (number % 1000 % 100)) / 100;
          digit3 = ((number % 100) - (number % 100 % 10)) / 10;
          digit4 = (number % 10);
          result = (digit1 * 8) + (digit2 * 4) + (digit3 * 2) + (digit4 * 1);
          System.out.println ( "Binary number: " + input + "\nConverted Decimal Number: " + result);
          System.exit( 0 );
     } // main
} // bintodecany help is super-appreciated.

I am not sure if this will help you. Check it out, run it and let me know if it helped.
import java.util.*;
   public class BitwiseTest1 {
       public static void main(String[] args){
        System.out.println("Enter a integer number:");
        Scanner keyboard = new Scanner(System.in);
        int n1 = keyboard.nextInt();
        System.out.println( "n1 as binary " +
               Integer.toBinaryString( n1 ));
        System.out.println( "NOT n1 =     " +
               Integer.toBinaryString( ~n1 ));
        System.out.println("Enter another integer number:");
        int n2 = keyboard.nextInt();
        System.out.println( "n2 as binary " +
               Integer.toBinaryString( n2 ));
         System.out.println( "NOT n2 =     " +
               Integer.toBinaryString( ~n2 ));
}

Similar Messages

  • Converting Binary to Decimal

    I would like to convert 12 and 32 digit strings into decimal. Is there
    a function in labview that does this? Does anyone have a vi (or sub-vi)?
    I'm using version 5.1
    Thanks!
    -DG
    [email protected]
    Sent via Deja.com
    http://www.deja.com/

    Hi Vinny,
    Thanks for the posting Vinny (and Stu). I did figure it out. The
    problem I initially had was that I had a 2-D array going into a for
    loop. I can break the array into 1-D arrays and then change this into
    an array into a string. No problems.
    Thanks!
    -DG
    In article <[email protected]>,
    vjrecca wrote:
    > hmmm, now I don't understand the question, because scan from string
    with a
    > %b format surely does take a string like "101101101110" and convert
    it to
    > decimal number 2926. Could you give a specific example of the string
    and
    > the expected result
    > - Vinny Recca.
    >
    > [email protected] wrote:
    >
    > > I've tried that, but to no success (I first convert the array into a
    > > sprea
    d sheet string, and then use the scan from string function.
    > >
    > > I did write a for while loop to do the conversion (basically using a
    > > shift register and putting the converted bits into an array that's
    > > built be the shift register, then adding them all up at the end).
    > >
    > > The numbers look off. Does Labiew intrinsically change the bits
    like
    > > from 0's to 1's when it's handling them?
    > >
    > > Thanks.
    > >
    > > -DG
    > >
    > > In article <_g3g6.76071$[email protected]>,
    > > "Stu McFarlane" wrote:
    > > > use the %b format string in the scan from string function (string
    > > functions)
    > > >
    > > > wrote in message news:95qec3
    > > $ekn$[email protected]..
    > > > > I would like to convert 12 and 32 digit strings into decimal. Is
    > > there
    > > > > a function in labview that does this? Does anyone have a vi (or
    sub-
    > > vi)?
    > > > >
    > > > > I'm using version 5.1
    > > > >
    > > > > Thanks!
    > > > >
    > > > > -DG
    > > > >
    > > > >
    [email protected]
    > > > >
    > > > >
    > > > > Sent via Deja.com
    > > > > http://www.deja.com/
    > > >
    > > >
    > >
    > > Sent via Deja.com
    > > http://www.deja.com/
    >
    >
    Sent via Deja.com
    http://www.deja.com/

  • Help converting binary to decimal.

    Hi all.
    I'm taking a course in Java programming and so far its been a great experience. I'm currently stumped on one of my assignments and I am kindly requesting some assistance.
    Basically I have to convert a binary entry into its decimal comparison.
    so for instance an entry of 1101 would output 13.
    I have the calculation formula, but my problem is finding out whether the point i'm looking at is either a 1 or a 0. I can't seem to 'strip it down' to the value.
    My current thought is something like this:
    binary = 1101;
    // problem is here
    thou = (binary % 1000) / 1000;
    hund = (thou % 100) / 100;
    tens = (hund % 10) / 10;
    ones = (tens % 1) / 1;
    // then do formular
    decimal = ones * 1 + tens * 2 + hund * 4 + thou * 8;
    I have searched but all the suggestions say to use a custom function or other obscure method. I don't know that stuff real well and we aren't even that far in the book either. All we've done so far is while, if .. else, condition statements.
    I will include the actual text for the question, in case i'm not clear. This text also includes a 'tip' which isn't helping me. (http://www.geocities.com/kaveman2000/q-4-25.pdf)
    Thanks again for any pointers.

    angeles1016 (and all),
    thanks for your great help and code snippets.
    angeles1016,
    using the code you provided i noticed that the last (single digit) was giving the wrong response in certain cases. (1000, 0111, 0001, ..) i could be off one.
    either way, i decided to fix it up and give you all the update.
    // do class, main function stuff
         if(binary/1000 == 1){
              thousands += (binary/1000);
         temp = binary % 1000;          
         if(temp/100 == 1){
              hundreds += (temp/100);
         temp = temp % 100;          
         if(temp/10 == 1){
              tens += (temp/10);
         temp = temp % 10;
         if(temp/1 == 1){
              ones += (temp/1);
         // calculate binary to decimal     
         decimal = (ones * 1) + (tens * 2) + (hundreds * 4) + (thousands * 8);
         // take result and convert to string for output
         result += "Decimal: " + decimal + "\n";
    // display in gui ?
    // end function and class stuff(note: i suppose the statements similar to "thousands += (binary/1000);" can be simplified as "thousands = 1;")

  • Convert binary to decimal

    hi, i was wondering what's the code to convert binary numbers to decimal numbers?

    import java.io.*;
    class convertBinarytoDecimal{
         public static void main (String args[])
         throws Exception {
              System.out.println("Enter the Binary Number");
              BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
              String str = br.readLine().trim();
              int [] myArray = new int [str.length()];
              for(int i=0;i<myArray.length;i++){
                   myArray[i] = Integer.parseInt(str.charAt(i)+"");
              convertBinarytoDecimal(myArray);
         static void convertBinarytoDecimal(int [] myArray){
              int decimal = 0;
              for (int i =0;i<myArray.length;i++){
                   decimal += myArray[i] * Math.pow(2,myArray.length-(i+1));
              System.out.println(decimal);
    }

  • Checking and Converting binary, octal, decimal, and hex

    Hi,
    I have a classroom project which will need to validate that data entered in a text is of a certain type with a keyListener, and then convert that value to the other 3 types.
    I know character.isDigit will handle the decimal case, and that I can then use Integer.otString methods to convert to binary, octal, and hex, but what about the other cases?
    Thanks

    OK, this isn't working. If I've already established
    that the string entered into, for example, the
    integer-only textfield is a valid integer, I should be
    able to simply use integer.parseint(s, 2) to convert
    it into binary, right?Not exactly. You should be able to use Integer.parseInt(s, 2) to return the result of converting it from binary representation. You appear to think that this affects whatever "s" refers to, which is not the case. Note also, that method returns an int which is the decimal value in question.
    When you are thinking of int variables, be careful not to think of them as "decimal" or "binary". They are neither. They are just numbers. "Decimal" and "binary" are text representations of numbers, so those concepts can only be applied to strings.
    Integer.parseInt(s, 2);
    txtBin.setText(s);So here you want to assume that the input is a string that represents a number in decimal, and you want to find the string that represents the number in binary. Like this:// convert string in decimal representation to number
    int dec = Integer.parseInt(s);
    // convert int to binary representation as string:
    String binary = Integer.toBinaryString(dec);
    // write that to the text field
    txtBin.setText(binary);You could use a one-liner to do that, but you'll need the "dec" variable to set the other text boxes.
    Rembering why I hate OO...All of what I said there is true in just about all computer languages, OO or otherwise.
    PC&#178;

  • Required code to convert binary to decimal

    i need the programming logic to convert a binary number into its decimal equivalent. the program should also detect a non binary number.

    public class EnterBinary{
       public static void main (String []args){
       int binCheck=0;
       String bins="";
       try {
          bins=args[0];
       catch (Exception e){
          System.out.print("No user input, program will terminate");
          System.exit(0);
       for(int i=0; i<bins.length(); i++)
          if((bins.charAt(i)=='1')||(bins.charAt(i)=='0')) binCheck++;
       if(binCheck==bins.length() ) {
          int j=1;
          binCheck=0;
          for(int i=0; i<bins.length()-1; i++) j *=2;
          for(int i=0; i<bins.length(); i++){
             if(bins.charAt(i)=='1') binCheck += j;
             j /=2;
       System.out.print("The binay number "+bins+" in decimal is "+binCheck);
       else System.out.print("Invalid binary input, program will terminate");
    }

  • How to convert fractional decimal number to hex number?

    Hi,
    Can any one help me to convert the fractional decimal number to its equivalent hex number and vice versa ?
    if u have any code please share.
    thanks
    neethu

    neethukk wrote:
    Can any one help me to convert the fractional decimal number to its equivalent hex number and vice versa ?
    if u have any code please share.
    This question is not clear at all.
    "Fractional decimal" is not a data type, but a way of formatting in readable form using numeric characters and a decimal separator.
    Same to "hex number", but only for integers.
    What do you mean by "convert"? Do you want to keep the value the same or retain the bit pattern of the numeric data type?
    Hexadecimal is for integers. Are you talking about fixed point?
    We clearly need significantly more information. What are the input and output data types? What are you actually trying to do?
    Do you have an example input and corresponding output?
    LabVIEW Champion . Do more with less code and in less time .

  • Help with binary to decimal, binary to hex, and hex to ascii or ascii to hex program

    I decided to do a program that will do binary to decimal, binary to hex, and hex to ascii for a project related to a java programming course, which only needs to perform features from chapters 1-6 and 8 of Tony Gaddis's book. The functions work fine as their own main programs out side of this combined effort, so can anyone help me determine why I get the following 41 errrors saying: class, interface, or enum expected as well as any other errors that may show up afterwards because I'm stumped. My flowcharts, which have to be revised after discovering that my previous function were logically incorrect after running them in their own main are attached below as the spec sheet.
    My code is as follows and I hope you don't mind the commented lines of unused code because I'm not sure where I want things and what I want at the moment:
    import java.util.Scanner;
    import java.io.*;
    import java.lang.*;
    public class BintoDectoHextoAscii
       public static void main(String[] args)throws IOException
          Scanner input = new Scanner(System.in);
          System.out.println("Enter a binary number: ");
          String binary = input.nextLine(); // store input from user
         if (binary == input.nextLine())
          //int i= Integer.parseInt(hex,2);
          //String hexString = Integer.toHexString(i);
          //System.out.println("Hexa decimal: " + hexString);
          //int finaldecimalvalue = binaryToDecimal(hexString);
          int finaldecimalvalue = binaryToDecimal(hexString);
         if (binary != input.nextLine())
          String hexInput; // The variable Bin Input declared as the datatype int to store the Binary value  
          // Create a Scanner object for keyboard input.
          //Scanner keyboard = new Scanner(System.in);
          // Get the number of binary files.
          System.out.print("Enter the Hex value: ");
          hexInput = keyboard.nextLine();
          System.out.println("Original String: "+ hexInput);
          //String hexEquivalent = asciiToHex(demoString);
          String hexEquivalent = asciiToHex(hexInput);
          //Hex value of original String
          System.out.println("Hex String: "+ hexEquivalent);
          String asciiEquivalent = hexToASCII(hexEquivalent);
          //ASCII value obtained from Hex value
          System.out.println("Ascii String: "+ asciiEquivalent);String finalhexOutput = HextoAsciiConverter(hexEquivalent);
         if (binary != input.nextLine() && hexInput != keyboard.nextLine())
             BufferedReader binInput = new BufferedReader(new InputStreamReader(System.in));
             System.out.println("Enter the Binary number:");
             String hex = binInput.readLine();
             //String finaldecimalvalue = binaryToDecimal(decimal);
             //long finalhexvalue = BinaryToHexadecimal(num);
             long finalhexvalue = BinaryToHexadecimal();
       public static String BinaryToHexadecimal(String hex)
          //public static void main(String[] args)throws IOException
             //BufferedReader bf= new BufferedReader(new InputStreamReader(System.in));
             //System.out.println("Enter the Binary number:");
             //String hex = binInput.readLine();
             long num = Long.parseLong(hex);
             long rem;
             while(num > 0)
             rem = num % 10;
             num = num / 10;
             if(rem != 0 && rem != 1)
             System.out.println("This is not a binary number.");
             System.out.println("Please try once again.");
             System.exit(0);
             int i= Integer.parseInt(hex,2);
             String hexString = Integer.toHexString(i);
             System.out.println("Hexa decimal: " + hexString);
          return num.tolong();
      //int i= Integer.parseInt(hex,2);
      //String hexString = Integer.toHexString(i);
      //System.out.println("Hexa decimal: " + hexString);
    //} // end BintoDectoHextoAsciil
       //public static String HexAsciiConverter(String hextInput)
          // Get the number of binary files.
          //System.out.print("Enter the Hex value: ");
          //hexInput = keyboard.nextLine();
          //System.out.println("Original String: "+ hexInput);
          //String hexEquivalent = asciiToHex(demoString);
          //String hexEquivalent = asciiToHex(hexInput);
          //Hex value of original String
          //System.out.println("Hex String: "+ hexEquivalent);
          //String asciiEquivalent = hexToASCII(hexEquivalent);
          //ASCII value obtained from Hex value
          //System.out.println("Ascii String: "+ asciiEquivalent);
       //} // End function  
       private static String asciiToHex(String asciiValue)
          char[] chars = asciiValue.toCharArray();
          StringBuffer hex = new StringBuffer();
          for (int i = 0; i < chars.length; i++)
             hex.append(Integer.toHexString((int) chars[i]));
          return hex.toString();
       private static String hexToASCII(String hexValue)
          StringBuilder output = new StringBuilder("");
          for (int i = 0; i < hexValue.length(); i += 2)
             String str = hexValue.substring(i, i + 2);
             output.append((char) Integer.parseInt(str, 16));
          return output.toString();
       public static String binaryToDecimal(String binary)
            //Scanner input = new Scanner(System.in);
            //System.out.println("Enter a binary number: ");
            //String binary = input.nextLine(); // store input from user
            int[] powers = new int[16]; // contains powers of 2
            int powersIndex = 0; // keep track of the index
            int decimal = 0; // will contain decimals
            boolean isCorrect = true; // flag if incorrect input
           // populate the powers array with powers of 2
            for(int i = 0; i < powers.length; i++)
                powers[i] = (int) Math.pow(2, i);
            for(int i = binary.length() - 1; i >= 0; i--)
                // if 1 add to decimal to calculate
                if(binary.charAt(i) == '1')
                    decimal = decimal + powers[powersIndex]; // calc the decimal
                else if(binary.charAt(i) != '0' & binary.charAt(i) != '1')
                    isCorrect = false; // flag the wrong input
                    break; // break from loop due to wrong input
                } // end else if
                // keeps track of which power we are on
                powersIndex++; // counts from zero up to combat the loop counting down to zero
            } // end for
            if(isCorrect) // print decimal output
                System.out.println(binary + " converted to base 10 is: " + decimal);
            else // print incorrect input message
                System.out.println("Wrong input! It is binary... 0 and 1's like.....!");
            return decimal.toint();
       } // end function
    The errors are as follows:
    ----jGRASP exec: javac BintoDectoHextoAscii.java
    BintoDectoHextoAscii.java:65: error: class, interface, or enum expected
       public static String BinaryToHexadecimal(String hex)
                     ^
    BintoDectoHextoAscii.java:73: error: class, interface, or enum expected
             long rem;
             ^
    BintoDectoHextoAscii.java:74: error: class, interface, or enum expected
             while(num > 0)
             ^
    BintoDectoHextoAscii.java:77: error: class, interface, or enum expected
             num = num / 10;
             ^
    BintoDectoHextoAscii.java:78: error: class, interface, or enum expected
             if(rem != 0 && rem != 1)
             ^
    BintoDectoHextoAscii.java:81: error: class, interface, or enum expected
             System.out.println("Please try once again.");
             ^
    BintoDectoHextoAscii.java:83: error: class, interface, or enum expected
             System.exit(0);
             ^
    BintoDectoHextoAscii.java:84: error: class, interface, or enum expected
             ^
    BintoDectoHextoAscii.java:87: error: class, interface, or enum expected
             String hexString = Integer.toHexString(i);
             ^
    BintoDectoHextoAscii.java:88: error: class, interface, or enum expected
             System.out.println("Hexa decimal: " + hexString);
             ^
    BintoDectoHextoAscii.java:90: error: class, interface, or enum expected
          return num.tolong();
          ^
    BintoDectoHextoAscii.java:91: error: class, interface, or enum expected
       ^
    BintoDectoHextoAscii.java:124: error: class, interface, or enum expected
          StringBuffer hex = new StringBuffer();
          ^
    BintoDectoHextoAscii.java:125: error: class, interface, or enum expected
          for (int i = 0; i < chars.length; i++)
          ^
    BintoDectoHextoAscii.java:125: error: class, interface, or enum expected
          for (int i = 0; i < chars.length; i++)
                          ^
    BintoDectoHextoAscii.java:125: error: class, interface, or enum expected
          for (int i = 0; i < chars.length; i++)
                                            ^
    BintoDectoHextoAscii.java:128: error: class, interface, or enum expected
          ^
    BintoDectoHextoAscii.java:130: error: class, interface, or enum expected
       ^
    BintoDectoHextoAscii.java:135: error: class, interface, or enum expected
          for (int i = 0; i < hexValue.length(); i += 2)
          ^
    BintoDectoHextoAscii.java:135: error: class, interface, or enum expected
          for (int i = 0; i < hexValue.length(); i += 2)
                          ^
    BintoDectoHextoAscii.java:135: error: class, interface, or enum expected
          for (int i = 0; i < hexValue.length(); i += 2)
                                                 ^
    BintoDectoHextoAscii.java:138: error: class, interface, or enum expected
             output.append((char) Integer.parseInt(str, 16));
             ^
    BintoDectoHextoAscii.java:139: error: class, interface, or enum expected
          ^
    BintoDectoHextoAscii.java:141: error: class, interface, or enum expected
       ^
    BintoDectoHextoAscii.java:144: error: class, interface, or enum expected
       public static String binaryToDecimal(String binary)
                     ^
    BintoDectoHextoAscii.java:150: error: class, interface, or enum expected
            int powersIndex = 0; // keep track of the index
            ^
    BintoDectoHextoAscii.java:151: error: class, interface, or enum expected
            int decimal = 0; // will contain decimals
            ^
    BintoDectoHextoAscii.java:152: error: class, interface, or enum expected
            boolean isCorrect = true; // flag if incorrect input
            ^
    BintoDectoHextoAscii.java:155: error: class, interface, or enum expected
            for(int i = 0; i < powers.length; i++)
            ^
    BintoDectoHextoAscii.java:155: error: class, interface, or enum expected
            for(int i = 0; i < powers.length; i++)
                           ^
    BintoDectoHextoAscii.java:155: error: class, interface, or enum expected
            for(int i = 0; i < powers.length; i++)
                                              ^
    BintoDectoHextoAscii.java:159: error: class, interface, or enum expected
            for(int i = binary.length() - 1; i >= 0; i--)
            ^
    BintoDectoHextoAscii.java:159: error: class, interface, or enum expected
            for(int i = binary.length() - 1; i >= 0; i--)
                                             ^
    BintoDectoHextoAscii.java:159: error: class, interface, or enum expected
            for(int i = binary.length() - 1; i >= 0; i--)
                                                     ^
    BintoDectoHextoAscii.java:166: error: class, interface, or enum expected
                else if(binary.charAt(i) != '0' & binary.charAt(i) != '1')
                ^
    BintoDectoHextoAscii.java:169: error: class, interface, or enum expected
                    break; // break from loop due to wrong input
                    ^
    BintoDectoHextoAscii.java:170: error: class, interface, or enum expected
                } // end else if
                ^
    BintoDectoHextoAscii.java:174: error: class, interface, or enum expected
            } // end for
            ^
    BintoDectoHextoAscii.java:180: error: class, interface, or enum expected
            else // print incorrect input message
            ^
    BintoDectoHextoAscii.java:185: error: class, interface, or enum expected
            return decimal.toint();
            ^
    BintoDectoHextoAscii.java:186: error: class, interface, or enum expected
       } // end function
       ^
    41 errors
    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

    so can anyone help me determine why I get the following 41 errrors saying: class, interface, or enum expected as well as any other errors that may show up afterwards because I'm stumped.
    Yes - YOU CAN!
    My code is as follows and I hope you don't mind the commented lines of unused code because I'm not sure where I want things and what I want at the moment:
    Excellent! Commenting out code is EXACTLY how you troubleshoot problems like yours.
    Comment out sections of code until the problem goes away. Then start adding back ONE SECTION of code at a time until the problem occurs. When it does you have just FOUND the problem.
    If you do that you wind up with code that looks like this:
    import java.util.Scanner;
    import java.io.*;
    import java.lang.*;
    public class BintoDectoHextoAscii  {
          public static void main(String[] args)throws IOException      {
             Scanner input = new Scanner(System.in);
             System.out.println("Enter a binary number: ");
             String binary = input.nextLine(); // store input from user
                  public static String BinaryToHexadecimal(String hex)     {     } // end function        
    Notice ANYTHING UNUSUAL?
    You have a complete CLASS definition followed by a method definition.
    Methods have to be INSIDE the class - you can NOT define methods on their own.
    Write modular code.
    Write EMPTY methods - just the method signature and maybe a RETURN NULL if you need to return something.
    Then add calls to those empty methods.
    When everything compiles and runs find you can start adding code to the methods ONE METHOD AT A TIME.
    Test compile and run after you add the code for each method.

  • Convert binary data to decimal in CAN XNET

    I am using NI-XNET Read function to read CAN frames from port CAN1 , the data out put comes in cluster in binary format is there any function that I can use to convert the binary to decimal ? I prefer not to write another sub-vi to do conversion but using the existing functions that can use my .dbc file and parse all frames in decimal format.
    Thanks.

    Yes Doug You are correct. We have a PCB and we have connected two inductive  sensors over the PCB which are measuring the distance and transpose it to voltage. The PCB has a software which transpose this voltage through an ADC and through the Can Bus we are reading the sensors .To communicate with the PCB  we are using a USB to Can device from IXXAT to communicate, we have build the Labview drivers and our problem as you mention is that we want to transpose this data to voltage. How we can do this? I try several times to upload photos or even the program we have create but for some reason the site is not letting me to do that. If you have an email i can send you the program we have create to tell us your opinion in this problem we have, we can also send you the Labview drivers and the datasheet of the sensor we are using.
    Attachments:
    Read from Can.vi ‏37 KB

  • Convert Mainframe Packed Decimal to Oralce Number Format

    Dear all,
    I am having a file in which amount fields are given in a Packed Decimal format. Can anyone suggest me how I can read this data element from the file and convert it into Oracle Number datatype.
    File is a fixed length. All the amount fields are given in Packed Decimal Format and rest of the fields are given in text format.
    Thanks and regards
    Nagasayan Puppala

    Hi,
    Firstly thanks for your reply.
    Actually I am not using SQL Loader to load data from
    a flat file to Oracle table. I am writing a custom
    program that reads the file and populates the oracle
    table. I'll put aside the question of 'why' you'd want to do that. SQL*Loader's singular purpose in life is to load flat files of data into Oracle DB. Sometimes there is a reason for reinventing the wheel.
    How does your program communicate with the Oracle DB? If utilizing ESQL and Pro*Cobol (or Pro*<whatever> ) you will have read the data into a variable of some type in you host language. The variable of the host variable to hold the value (if you did a 'select from' that table) would be the correct target type for an insert statement. Whatever host language type conversion is available bewteen those two types ( if they are different at all ) is all that is needed. The precompilers have converters between certain native host and internal Oracle types built-in. It is how you get any data between the two systems. This is only a problem if the host language has no converter between the numeric types (if differnet.). When you read from the flat file are you reading it into a native packed decimal in the host language?
    ODBC/JDBC similar strategy..... cast conversion between the native type that Oracle wants and the one into which your custom program reads it into.
    So I want to know whether there are any Oracle
    utility programs that will convert the packed decimal
    to a oracle number format or not.There are Oracle routines that convert into the native Oracle DB formats. There are implicitly available through the normally utilized interfaces to OCI ( ESQL and ODBC/JDBC ) . There are none decoupled from those interfaces though (that I know of).
    There are no standalone programs that mutate a flat file into another flat file that then could be loaded. That's is typically slower and utilzes more space than most customers want than just directly inputing the data into Oracle DB.
    Message was edited by:
    lytaylor

  • 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));

  • How to convert data read in byte to decimal number?

    The following are a source code to read from a serial port, but i can't convert the data that i read to decimal number and write it on a text file.....can anyone kindly show me how to solve it? thanks
    import javax.comm.*;
    import java.io.*;
    import java.util.*;
    public class Read implements Runnable, SerialPortEventListener {
         // Attributes for Serial Communication
         static Enumeration portList;
         static CommPortIdentifier portId;
         SerialPort serialPort;
         static OutputStream outputStream;
         InputStream inputStream;
         Thread readThread;
         public static void main(String s[])
         portList=CommPortIdentifier.getPortIdentifiers();
         while(portList.hasMoreElements())
              portId=(CommPortIdentifier)portList.nextElement();
              if(portId.getPortType()==CommPortIdentifier.PORT_SERIAL)
                   if(portId.getName().equals("COM1"))
                        System.out.println( portId.getName());
                        Read ss=new Read();
              }     // end of while
    }          // end of main
    public Read()     {
    try{
              serialPort=(SerialPort)portId.open("Read", 2000);
    catch(PortInUseException e)     {}
         try{
              inputStream=serialPort.getInputStream();
              System.out.println(inputStream);
    catch(IOException e)     {}
         try{
              serialPort.addEventListener(this);
    catch(Exception e)     {}
              serialPort.notifyOnDataAvailable(true);
         try{
              serialPort.setSerialPortParams(9600,
              SerialPort.DATABITS_8,
              SerialPort.STOPBITS_1,
              SerialPort.PARITY_NONE);
              }catch(UnsupportedCommOperationException e)     {}
              readThread=new Thread(this);
              readThread.start();
         }//end of constructor
         public void run()
              try     {
                   Thread.sleep(200);
              }catch(InterruptedException e)     {}
         public void serialEvent(SerialPortEvent event)
              switch(event.getEventType())
                   case SerialPortEvent.BI:
                   case SerialPortEvent.OE:
                   case SerialPortEvent.FE:
                   case SerialPortEvent.PE:
                   case SerialPortEvent.CD:
                   case SerialPortEvent.CTS:
                   case SerialPortEvent.DSR:
                   case SerialPortEvent.RI:
                   case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
                   break;
                   case SerialPortEvent.DATA_AVAILABLE:
                   byte[]readBuffer=new byte[8];
                   try{
                        while(inputStream.available()>0)
                             int numBytes=inputStream.read(readBuffer);
                             //System.out.println("hello");
                        System.out.print(new String(readBuffer));
                        }catch(IOException e)     {}
                   break;
                   }     // end of switch
                   try     {
                        inputStream.close();
                        }catch(Exception e5)     {}
         }          // end of serialEvent

    Is it a float or a double?
    For a float, the decimal should be 4 bytes (small numbers like 1.1 start with the byte 0x40). Convert these 4 bytes to an int, using byte-shifting would probably be easiest.
    int value = ((b3 << 24) + (b2 << 16) + (b1 << 8) + b0);//b# are bytesNow to convert it to a float, use
    Float.intBitsToFloat(value);Now if you want double percision, You will have 8 bytes instead of 4, and need to be converted to a long instead of an int through byte-shifting. Then use Double.longBitsToDouble(long bits) to get the double

  • Regarding Converting the Decimal number into rounded value...

    Hi,
       i have a decimal number as "   58240990.00 " , i wanted this to rounded value .
      for example I am expecting to see 58241 for the above number.
      shell we can do in any way.. if so please let me knw fast.. it is urgent..
      thanks in advance.
    thanks,
    Suresh..

    Dear Suresh,
    Go through the following code chunk:
    DATA : p TYPE p DECIMALS 2 VALUE '2.49'.
    DATA i TYPE i.
    i = CEIL( p ).
    WRITE : i.
    Regards,
    Abir
    Don't forget to award Points *

  • Binary to Decimal problems

    Ok to give a background to why i am writing this and so everyone has a better understanding of exactly what it is that i want it to do it goes like this.... My girlfriend got a message from a friend that was all in ones and zeros, and no its not because something on one of the mail servers is messed up he meant for it to be that way. But through the process of converting the 8 digit binary numbers into decimal values so that the corresponding ANSI character could be found I decided that it was taking to damn long so i would just write a prog to do it for me and then i could send back an annoying long message to that guy with ease. Only there is a catch over the summer i went from hotshot for a newb to a newb without a clue, i more or less didnt write a single line of code over 4 months and now i am having problems.
    I wanted to write a program that could-
    -convert long strings of chars into all 8 digit binary code
    -as well as convert large blocks of 8 digit binary back into ANSI letter values and then ANSI characters
    -I want it to use a frame and have a relativly simple usage procedure
    Now that you know what i set out to do I can show you how far i got -
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.GradientPaint.*;
    public class BinaryToDec extends JFrame implements ActionListener
         // member variables
         JButton quit;
         JButton color;
         JButton convert;
         JLabel     label11_5, labelPassingWord;
         JTextField inputBinary, outputDecimal;
         Color      colorStore;
         String drawString;
         String bin;
         public BinaryToDec()
              drawString = "";
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setLocation(100,250);
              setTitle("Binary to Decimal");
              setSize(420,200);
              getContentPane().setBackground(Color.BLACK);
              getContentPane().setLayout(null);
              quit= new JButton("DONE");
              quit.setForeground(Color.GREEN);
              quit.setBackground(Color.BLACK);
              quit.setBounds(100,10,75,20);
              getContentPane().add(quit);
              quit.addActionListener(this);
              color= new JButton("Bkgnd Clr");
              color.setForeground(Color.GREEN);
              color.setBackground(Color.BLACK);
              color.setBounds(15,10,75,20);
              getContentPane().add(color);
              color.addActionListener(this);
              convert= new JButton("Convert to Decimal");
              convert.setForeground(Color.GREEN);
              convert.setBackground(Color.BLACK);
              convert.setBounds(185,10,75,20);
              getContentPane().add(convert);
              convert.addActionListener(this);
              label11_5 = new JLabel("Enter a Binary Number");
              label11_5.setBounds(75,60,250,20);
              label11_5.setForeground(Color.GREEN);
              getContentPane().add(label11_5);
              inputBinary = new JTextField(25);
              inputBinary.setBounds(5,40,225,20);
              inputBinary.setForeground(Color.BLACK);
              getContentPane().add(inputBinary);
              inputBinary.addActionListener(this);
              labelPassingWord = new JLabel("Your Deciaml Equivilant");
              labelPassingWord.setBounds(75,120,250,20);
              labelPassingWord.setForeground(Color.GREEN);
              getContentPane().add(labelPassingWord);
              outputDecimal = new JTextField(25);
              outputDecimal.setBounds(5,100,225,20);
              outputDecimal.setForeground(Color.BLACK);
              getContentPane().add(outputDecimal);
              outputDecimal.addActionListener(this);
              setVisible(true);
         }// end of constructor
         public void actionPerformed (ActionEvent evt)
              if(evt.getActionCommand().equals("DONE"))
                   System.out.println("Quit Caught");
                   int choice = JOptionPane.showConfirmDialog(null , "You Pressed " + evt.getActionCommand() + " are you sure?"
                        , "Close Frame",JOptionPane.YES_NO_OPTION);
                   if(choice == 0)
                        this.dispose();
                   if (evt.getSource() == color)
                        Color color = Color.lightGray;
                        color = JColorChooser.showDialog(BinaryToDec.this,"Choose a color",color);
                        getContentPane().setBackground(color);
                   if (evt.getSource() == convert)
                        bin = inputBinary.getText();
                        int strLength = bin.length();
                        int pos1=0, pos2=7;
                        String temp = "";
                        String Decimal1 = "";
                        String Decimal2 = "";
                        int binLength = 8;
                        int count = 0;
                             do
                                  temp = bin.substring(pos1,pos2);
                                  Decimal1 = Convert(temp);
                                  Decimal2 = Decimal2 + "" + Decimal1;
                                  pos1 = pos1 + binLength;
                                  pos2 = pos2 + binLength;
                                  count++;
                                  outputDecimal.setText(Decimal2);
                                  repaint();
                             }while((strLength/8) >count);
         }//end of actionPerform
         public void paint( Graphics g)
              super.paint(g);
         public String Convert(String a)
              int ctr=1, decimal=0;
              for (int i = a.length()-1; i>=0; i--)
              if(a.charAt(i)=='1')      decimal+=ctr;
              ctr*=2;
              String converted = "" + decimal;
              return converted;
         public static void main(String args[])
              System.out.println("Binary to Dec");
              BinaryToDec in = new BinaryToDec();
         }// end of main()
    }// end of class FrameExample1
    OK so other than that i decided to play with some of the paint functions i more or less stayed on task, at first i had it just convert 8 digit binary nums into decimal form using this -
              int ctr=1, decimal=0;
              for (int i = a.length()-1; i>=0; i--)
              if(a.charAt(i)=='1')      decimal+=ctr;
              ctr*=2;
    which i found in someone elses post and made some changes to, thank you someone whoever you are i hope you see this, anyways,.. then i decided i wanted it to check the length of a string and divide it by 8 assuming that it it a perfect block of 8 digit nums and then cut it into substring and go through the proccess of converting the binary to deciaml one piece at a time. I did it more or less, well it compiles right but whenever you put in more than one 8 digit binary number it ends up giving you some really strange decimal numbers and i cant seem to figure out why the hell it is doing this.??? I was hoping that some one could help me out.
    If you read this far than thanks for taking the time on my post :)

    Did you try to decode that message by hand and verified that it really is encoded the way you think it is?
    Here some code to try
    public static void decode(String fileIn, String fileOut) {
            try {
            FileReader in=new FileReader(fileIn);
            PrintWriter out=new PrintWriter(fileOut);
            char[] buffer=new char[8];
            int i;
            do {
                i=in.read(buffer, 0, 8);
                if(i==8) {
                    out.write(Integer.parseInt(new String(buffer),2));
            } while(i==8);
            in.close();
            out.close();
            } catch (Exception e) {}
        public static void encode(String fileIn, String fileOut) {
            try {
            FileReader in=new FileReader(fileIn);
            PrintWriter out=new PrintWriter(fileOut);       
            int i;
            while( (i=in.read()) >= 0 ) {
                String str=Integer.toBinaryString(i);
                for(int j=str.length(); j<8; j++)
                    out.write('0');
                out.write(str);
            in.close();
            out.close();
            } catch (Exception e) {}
        }

  • Converting binary to floating point?

    ok, i am programming a little java program at the consulter
    the main idea of the program is to convert a decimal number to IEEE (floating point)
    i am almost done except the exponent part
    i dont understand the logic behind it
    so, for example:
    -6.625 = 110.101 (binary)
    after normalization it will be -1.10101 * 2^2
    so the IEEE will be
    1 10000001 10101000000000000000000
    i understand the sign part and the fraction part
    but i have no idea how the exponent part came like this
    the book say that 129-127=+2 so the exponent is 10000001
    da, where it came from ???
    i will appreciate it if someone explain this part for me step by step
    thank you,
    Edited by: abdoh2010 on Jan 26, 2008 2:37 AM

    got it
    thank you for viewing my question

Maybe you are looking for

  • Report for invoices project wise

    Hello All, I need a report where I can see the invoices project wise i.e (PS module and SD module) I am looking for invoices details project wise is there any standard report which I can check that how many invoices have been raised for  a particular

  • Active Directory requires display name for log in not logon name

    I have a weblogic 10 server and I have created an Active directory authenticator. I can list the users and groups in the console. The problem is that I can only logon using the Display name e.g. "Smith, Fred" and not the logon name e.g. "smithf" I wo

  • Aironet 350 reset to factory config over vacation.

    I have an Aironet 350 non-root bridge that was reset back to its factory default configuration over a 5 day period of inactivity (Christmas vacation). I didn't set it up, so I can't say too much about how it was configured before except that it was r

  • SDM is not installed.

    Hi All, I am facing a strange problem here. In a server some one installed EP6.0 sp11. but SDM is not installed. normally SDM should be installed in :\usr\sap\EP\JC01\SDM but i dont see this in this installation. Can we install SDM separately? What i

  • Please help with ENGLISH names for extd details

    Please can anyone with an ENGLISH OS (en-xx, Sub langID should all be the same ?? i guess) run the following lines and post the result. tab = Text.GetCharacter(9) tmpFile = File.GetTemporaryFilePath() allDetails = LDShell.AllDetails nDetails = Array.