Converting to base 10

My instructions were:
Write a function, public int convertToBase10(String s) which takes a
String that represents the String form of a binary number and returns an int which
is equal to this number in base 10. For example, convertToBase10(�1001�)
returns 9.
Can anyone point me in the right direction?
double sum = 0, exp = 0;
public int convertToBase10(String s) {
     if (s.length() >= 1)
     String current = charAt(s.length());
     int num = Integer.parseInt(current);
     sum = sum + (java.lang.Math.pow(2,exp) * num);
     exp++;
     convertToBase10(s.substring(0,(s.length() - 1)));
     return sum;
}

                String str = "1001";
          int num = 0;
          for (int x=0; x<str.length(); x++){
               int c = str.charAt(x)-48;
               int d = (int)Math.pow(2,x);
               num = num + c * d;
          System.out.println(num);str.charAt(x) always returns me the ASCII.
Anyways this works.

Similar Messages

  • Convertion of Base tables to Material views while executing dbms_refreshes

    Hi all,
    I have a typical type of problem. We have a daily task of database activities like monitoring the space, refreshing Material views etc and currently using While doing refreshing the materialized views (using dbms.refresh) All master tables are become MV's in the database.This is a serious issue has to be solved asap.
    Also I find the materialized views got some data's in it. Now I want to get my master tables back to original.
    I have an idea to drop all the respective base tables, materialized view and recreate the same once again.
    But Is there any other alternate method there to get back my materialized views converted to base tables???
    Can someone help me how to do the same????
    Thanks in advance.
    Regards
    Dinesh

    While doing refreshing the materialized views (using dbms.refresh)
    All master tables are become MV's in the database?????
    So strange that I'd say that's not possible. How did you check that ? and which command did you execute exactly ?

  • Convert any base number to decimal

    Is there a way to convert any number of base 2-16 into decimal?
    The numbers can be input using scanner
    Anyone has any code for this?

    Hey, guys this is what I got so far for this. But, of course there are issues
    1. I'm not sure how to show "invalid" message if a character or floating point number is entered
    2. I'm not sure about the code that will only allow the relevant numbers to be entered for each base.
    E.g - If base = 2 then number == 1 || 0
    This has to be repeated for all allowed base from 2-16
    Please help!!!
    import java.util.Scanner;
    public class BaseConverter {
    public static void main(String[] args) {
    int base;
    String number;
    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter base value (Integer between 2 to 16): ");
    base = scanner.nextInt();
    if (base < 2 || base > 16) {                     // how to get same invalid message for character or float (e.g. -12.2)
    System.out.println("Invalid base. Please retry");
    return;
    System.out.print("Enter the number in base : ");
    number = scanner.next();
    if (scanner.hasNext()) {           // not sure how to validate in relation to entered base
    } else {
    System.out.println("Invalid number. Please retry");
    return;
    int decimalValue = 0;
    int step = 0;
    for (int i = number.length() - 1; i >= 0; i--) {
    char c = number.charAt(i);
    int cValue = Character.digit(c, base);
    decimalValue = decimalValue + (cValue * (int) Math.pow(base, step));
    step = step + 1;
    System.out.println("Decimal value: " + decimalValue);
    }

  • Converting one  base unit of measure to another

    Hi Experts,
    i want to know the function module name , which should convert the one base unit of mesure to another base unit of measure.
    like EA TO PAL , or PAL TO sqft.
    i have found one function module ( MATERIAL_UNIT_CONVERSION) ,which is not giving proper output(giving only zero's)
    could u please help me out from this problem.
    Thanks in Advance,

    Hello,
    Try this.
    data:c_kg LIKE lips-gewei VALUE 'KG', "Weight unit in kg
    c_lb LIKE lips-gewei VALUE 'LB', "Weight unit in lb(pound).
    CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
    EXPORTING
    input = i_ln_items-brgew
    unit_in = c_kg
    unit_out = c_lb
    IMPORTING
    output = i_ln_items-brgew_lb.
    If useful reward.
    Vasanth

  • Converting from BASE 64 to Decimal Base 10

    I have an requirement to convert a value from base 64 to decimal base 10
    for ex if i give b the resultant output should be 27
    as per the website -- http://convertxy.com/index.php/numberbases/
    I tried using the UTL_ENCODE.BASE64_ENCODE with UTL_RAW.CAST_TO_RAW
    select utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw('b'))) from dual
    but i am not getting the desired result
    Kindly guide me in this issue
    With Warm Regards
    SSR

    The base64 encoding for 27 is not b
    SELECT UTL_RAW.cast_to_varchar2 (
              UTL_ENCODE.base64_encode (
                 UTL_RAW.cast_to_raw (
                    '27')))
              base64
      FROM DUAL
    BASE64
    "Mjc="27 ist the position of b in
    ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
    which you need in the first step to convert base64 to decimal.
    select
    instr(
      'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
    ,'b'
    ) -1 d
    from dual
    d
    27
    vice versa
    select
    substr(
      'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
      ,27 + 1
      ,1
    ) d
    from dual
    D
    "b"You dont get a result with your approach because b is not a valid base64-encoding.
    Otherwise thsi should give a result
    SELECT UTL_RAW.cast_to_varchar2 (
              UTL_ENCODE.base64_decode (
                 UTL_RAW.cast_to_raw (
                    'b')))
              base64
      FROM DUAL
    BASE64
    but it doesnt, it does in the case below
    SELECT UTL_RAW.cast_to_varchar2 (
              UTL_ENCODE.base64_decode (
                 UTL_RAW.cast_to_raw (
                    'Mjc=')))
              base64
      FROM DUAL
    BASE64
    "27"Edited by: chris227 on 12.03.2013 07:36
    Edited by: chris227 on 12.03.2013 07:41
    Edited by: chris227 on 12.03.2013 07:46
    Edited by: chris227 on 12.03.2013 08:20

  • How can I convert NIDAQ32.bas to *.vb?

    I'm using Data Acquisition (PCI-6040E) and version NI-DAQ 6.9.3 that supported Window XP but not mesurement studio.
    This interface card works good for Microsoft Visual Basic 6.0 but Microsoft Visual Basic .net not works with it because VB.net is not supported 'As Any' in 'Declare' statements of nidaq32.vb
    for example, I tried to convert syntax
    Declare Function SCAN_Op% Lib "nidaq32.dll" (ByVal a%, ByVal b%, ByVal c%, d%, e%, ByVal f&, ByVal g#, ByVal h#)
    to syntax
    Declare Function SCAN_Op% Lib "nidaq32.dll" (ByVal a%, ByVal b%, ByRef c As Integer, ByRef d As Integer, ByRef e As Integer, ByVal f&, ByVal g#, ByVal h#).
    But When I Compiled, the error is broken out.
    What's Wrong with my cpnversion?
    if anyone ask for my quwstion
    , it's very helpful to me.
    Thank you very much.

    VB6 supported As Any in Declare statements for functions with parameters that could support more than one data type. The way to do this in VB.NET is to overload the Declare statement with the different types you want to use for a specified parameter. For more information see these topics from MSDN:
    Upgrade Recommendation: Adjust Data Types for Win32 APIs
    Declare statement does not support parameters of type As Any
    - Elton

  • Casting base class object to derived class object

    interface myinterface
         void fun1();
    class Base implements myinterface
         public void fun1()
    class Derived extends Base
    public class File1
         public myinterface fun()
              return (myinterface) new Base();
         public static void main(String args[])
              File1 obj = new File1();
              Derived dobj = (Derived)obj.fun();
    Giving the exception ClassCastException......
    Can't we convert from base class object to derived class.
    Can any one help me please...
    Thnaks in Advance
    Bharath kumar.

    When posting code, please use tags
    The object returned by File1.fun() is of type Base. You cannot cast an object to something it isn't - in this case, Base isn't Dervied. If you added some member variables to Derived, and the compiler allowed your cast from Base to Derived to succeed, where would these member variables come from?
    Also, you don't need the cast to myinterface in File1.fun()
    Also, normal Java coding conventions recommend naming classes and interfaces (in this case, myinterface) with leading capital letters, and camel-case caps throughout (e.g. MyInterface)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Converting hexadecimal XML data to a string

    Hello!
    Until now I generated XML data with the FM 'SDIXML_DOM_TO_XML'.
    After that I did a loop over the xml_as_table in which I was casting each line of that table to a string.
    ASSIGN <line> TO <line_c> CASTING.
    After the inftroduction of unicode in our system I get a error:
    In the current program an error occured when setting the field symbol <LINE_C> with ASSIGN or ASSIGNING (maybe in combination with the CASTING addition).
    When converting the base entry of the field symbol <LINE_C> (number in base table: 32776), it was found that the target type requests a memory alignment of 2
    What does it mean? Does somebody have a solution.
    I need this function for sending this XML data as string over a simple old CPIC connection.
    Best regards
    Martin

    Hello Martin
    Perhaps my sample report ZUS_SDN_XML_XSTRING_TO_STRING provides a solution for your problem.
    *& Report  ZUS_SDN_XML_XSTRING_TO_STRING
    *& Thread: Converting hexadecimal XML data to a string
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1029652"></a>
    REPORT  zus_sdn_xml_xstring_to_string.
    *-- data
    *-- read the XML document from the frontend machine
    TYPES: BEGIN OF xml_line,
            data(256) TYPE x,
          END OF xml_line.
    DATA: xml_table TYPE TABLE OF xml_line.
    DATA: go_xml_doc       TYPE REF TO cl_xml_document,
          gd_xml_string    TYPE string,
          gd_rc            TYPE i.
    PARAMETERS:
      p_file  TYPE localfile  DEFAULT 'C:payload_idoc.xml'.
    START-OF-SELECTION.
      CREATE OBJECT go_xml_doc.
      " Load XML file from PC and get XML itab
      CALL METHOD go_xml_doc->import_from_file
        EXPORTING
          filename = p_file
        RECEIVING
          retcode  = gd_rc.
      CALL METHOD go_xml_doc->get_as_table
        IMPORTING
          table   = xml_table
    *      size    =
    *      retcode =
    " NOTE: simulate creation of XML itab
      go_xml_doc->display( ).
      create object go_xml_doc.
      CALL METHOD go_xml_doc->parse_table
        EXPORTING
          table   = xml_table
    *      size    = 0
        receiving
          retcode = gd_rc.
      CALL METHOD go_xml_doc->render_2_string
    *    EXPORTING
    *      pretty_print = 'X'
        IMPORTING
          retcode      = gd_rc
          stream       = gd_xml_string
    *      size         =
      write: / gd_xml_string.
    END-OF-SELECTION.
    Regards
      Uwe

  • Base 26 to Base 10 Java Code - Realbasic Equivalent?

    I was looking at this article on wikipedia that includes two java algorithums for converting a base 26 number (letters) into a base ten number (0-10) and back again. Does anyone know how to translate this into realbasic code?
    What I am looking to do is use a updownarrow control to allow the user to increase or decrease the value of a base 26 number in an editfield by clicking on the updownarrowcontrol. What I need to do is convert the base 26 number into a base 10 base, add or subtract 1, and covert it back into a base 26 number for display in the editfield. Thus aa would become ab if increased by 1 or it would become z if decreased by 1. Conversely zz would become aaa (+1) or zy (-1).
    http://en.wikipedia.org/wiki/Hexavigesimal
    public static String toBase26(int number){
    number = Math.abs(number);
    String converted = "";
    // Repeatedly divide the number by 26 and convert the
    // remainder into the appropriate letter.
    do
    int remainder = number % 26;
    converted = (char)(remainder + 'A') + converted;
    number = (number - remainder) / 26;
    } while (number > 0);
    return converted;
    public static int fromBase26(String number) {
    int s = 0;
    if (number != null && number.length() > 0) {
    s = (number.charAt(0) - 'A');
    for (int i = 1; i < number.length(); i++) {
    s *= 26;
    s += (number.charAt(i) - 'A');
    return s;
    }

    You can replace the first one with Integer.parseInt("....", 26), and the second one with Integer.toString(int, 26).
    Translation of the code you posted into other languages is (a) trivial and (b) beyond the scope of this forum.

  • How to convert base64 data to an image

    Hello, my enterprise application is receiving base64 enocoded image data in an xml file. Now I need to convert it to a native image formats like jpeg/jpg/tiff/pdf etc. Does anybody know if there are any Java apis (both free/paid) which let you do this. Actually I would not have any idea of what type of image it was when it was initially encoded to base64 format. I am looking for an API/technique that can convert base64 data to any image depending on what I want at runtime.
    Thanks a lot in advance.
    R

    Hi there,
    I've had to deal with exactly the same problem myself. The images I had to deal with were all TIFF files, and that was okay, I'd say one of your first steps would be to find out what format these images are in.
    I used a SAX Content Handler to pull the base 64 image data out of the XML into a String, and then converted the Base 64 String into a byte array. From there I could either simply write the byte array to a file, or if I wanted use ImageIO to create an Image object, work with the metadata or even save it in a different format, though I never actually did that.
    Anyway, here is some code I whipped up to convert the String to a byte array, then write the byte array to disk. Let us know how you get along!
          * Writes a byte array to a file.
          * @param result          String containing base64 image data     
          * @param fileName     File name to write the converted image to
         public static void writeTiff(byte[] result, String fileName) throws IOException {          
              FileOutputStream out = new FileOutputStream(fileName, true);
              out.write(result);
              out.close();
          * Converts a String of base 64 image data, captured from XML, into a byte array.
          * @param      image     A Base 64 String          
          * @return      byte[]          
         public static byte[] convertTiff(String image) throws IOException {          
              byte[] result = new sun.misc.BASE64Decoder().decodeBuffer(image);
              return result;
         }

  • Conversion of Order Unit to Base Unit

    Hi Friends,
    How to set the conversion of Order Unit to Base unit.
    The scenario is like this.  Purchase order is made in Rolls but the stocking will be in meter.   I my case, when the GR is made in meter, the rolls should be multiplied by 65.  Instead the system is dividing the rolls by 65 meters which is wrong.
    I want to correct same, but dont know where to do.
    Kindly guide me to correct this.
    TIA.
    Regards,
    Mark K

    Hi Mark,
    You can only change the base units of measure under the following circumstances
    • No stocks are available for the material.
    • There are no existing purchase requisitions, purchase orders, or scheduling agreements for the material.
    • At present, no purchase orders or purchase order items are being created or changed.
    If requests for quotations, purchasing info records, or contracts are available for a material, the system emits a warning while changing base unit of measure. Still if you want to change unit of measure specify in a dialog box the factor for converting the base unit of measure into the new base unit of measure. The purchasing info records are then, if necessary, updated.
    As system is not allowing changing base unit of measure there will be either stock of this material or existing purchase document
    1) If there are stocks in the previous period, you can clear them as follows:
    a) Post the stock in the previous period to the current period (for example, using movement type 561) so that the stock for the previous period is the same as the stock for the current period.
    b) Clear the stock with the posting date in the previous period (for example, using movement type 562).
    • 2) If there are Open purchase requisitions, purchase orders, or scheduling agreements for the material.
    We suggest completing all P2P cycle for open orders (purchase requisitions, purchase orders, or scheduling agreements) and then close it.
    Then
    1. Run Trnx MM02 (Change Material Master immediately.
    2. Overwrite the old base unit of measure with the new one in basic data screen.
    3. Save the change.
    Reward points for helpful.
    Regards,
    Harini.S

  • Pblm in Converting BUOM to Batch specific unit of measure

    Hi Gurus
    I am Facing a Problem in converting the base unit of measure to batch specific unit of measure.
    I have given BUOM in KG.Batch specific unit of measure is PC.
    When i do GR for the material in KG with the average wt of the material in kg in the classification view
    the system is increasing my GR KG to convert the material to PCS .
    I dont want KG to be increased but the PCs to be rounded off to next integer.
    How can i resolve this pblm??
    NB:- All the settings are done correctly
    and all the notes are applicable in ECC 604
    Thanks and Regards
    BS

    Dear
    Did you assing any Rounding value and Rouding Profile in MRP1-MM01 for this item ?? Do not maintained this option in MRP1 and check wether you have Kept rouing vadule against KG in CUNI ??
    Basically , if you maintain the profile then it will rounds up to the next level based on the thresold valu as configuired in your case in Rouidng Profile  in OWD1 .
    Also check in MM-Purcahsing -Order Optimisation -Unit of Measure of Rounding rules  for  purchased item .This based on the control of optimisation of qty.
    Hope it helps
    Regards
    JH

  • Changes in Base Unit of Measure

    Hi,
    We got an issue,User tried to change the Base unit of Measure from NO to KG.
    1.For this material we dont have stock in unrestricted and quality,But it has reservations. 2.It has got Scheduling agreement,3.This material is used In BOM.
    So if i cancel reservations,then remove this item from scheduling agreement and delete it from BOM.Will it work further to change the Base Unit of Measure.
    Please Do help me in this matter
    Thanks and Regards

    1) You can only change the base units of measure under the following circumstances
    •No stocks are available for the material.
    •There are no existing purchase requisitions, purchase orders, or scheduling agreements for the material.
    •At present, no purchase orders or purchase order items are being created or changed.
    •Item is not linked in any BOM as chield part
    If requests for quotations, purchasing info records, or contracts are available for a material, the system emits a warning while changing base unit of measure. Still if you want to change unit of measure specify in a dialog box the factor for converting the base unit of measure into the new base unit of measure. The purchasing info records are then, if necessary, updated.
    2)  Solution
       As system is not allowing changing base unit of measure there will be either stock of this material or existing purchase document
    1) If there are stocks in the previous period, you can clear them as follows:
    a) Post the stock in the previous period to the current period (for example, using movement type 561) so that the stock for the previous period is the same as the stock for the current period.
    b) Clear the stock with the posting date in the previous period (for example, using movement type 562).
    2) If there are Open purchase requisitions, purchase orders, or scheduling agreements for the material.complete all P2P cycle for open orders (purchase requisitions, purchase orders, or scheduling agreements) and then close it.
    3)Delete item from BOM
    Then
    1.     Run Trnx MM02 (Change Material Master immediately.
    2.     Overwrite the old base unit of measure with the new one in basic data screen.
    3.     Save the change.
    3) System checks
    If a change criterion (Trnx. code MM02) is meeting all necessary prerequisites (as mentioned in point 1).System allows changing base unit of measure. Otherwise it displays warning or error. U can display the reason for this, by choosing Display Errors (ctrl+F1)

  • Base 128 Conversion

    I am looking for an algorithm to convert a base 128 number into a base 10 number.
    Example:
    Learn from the mista
    should become
    836223910068639560092299063760172789594721
    I am having a hard time coming up with a conversion algorithm, b\c of the ASCII characters subbed in for digits after a point in base 128. I would appreciate any help you can give me.
    Stephen

    I'm trying to do this same thing, and I'm messing up badly. This is the code I have:
    String message = "abc";
    char c = ' ';
    BigInteger bigInt = new BigInteger();
    for (int j = message.length() - 1; j >= 0; j--)
    c = message.charAt(j);
    double ascii = ((double)c) * Math.pow(128.0, exp);
    bigInt = bigInt.add(BigInteger.valueOf((long)ascii));
    exp++;
    And that, I'm sure you can tell, is not working. I have absolutely no idea what to do.
    Like Stephen, I have to have an algorithm that will convert the string:
    "Learn from the mista" and convert it into the BigInteger:
    836223910068639560092299063760172789594721
    Any help at all would be appreciated.

  • Fibre Base to Spatial conversion

    Can anyone please advise on how to convert Fibre Base data to Spatial. Is there any off the shelf software for this process.
    Thanks
    Bob
    [email protected]

    r u looking to convert from eucledian base data ... I may need
    little bit more info about FIBRE BASE to suggest.
    Ram

Maybe you are looking for

  • Error in Background job for Status refresh after SP15

    Hi, I am having a issue after applying SP 15 in our Solman Production. Bckg Job REFRESH MESSAGE STATUS for refereshing message status which was working fine uptil SP10 now its giving us following error At least one entry could not be found in object

  • Can I run a factory reset on my MacBook Pro and later reinstall my purchased apps, or will I have to pay for them again?

    My MacBook Pro is a work computer, and my company may need to run a factory reset on it. I don't have much faith in their abilities to save any of my info, so I am backing all my photos and videos up on an external hard drive, but I am concerned I wi

  • BOE XI 3.1 using IIS

    We are building a new BOE XI 3.1 using IIS as the web server, windows AD authentication and Kerberos for SSO.  At this point we have run into two issues:  1. we can't configure Windows AD authentication for the CMC login.  We would also like to use S

  • OS X freezes

    Hello - I want to see if anyone else is experiencing this issue I've been experiencing for almost two weeks now. After the system update last week, my MBP OSX freezes up randomly. My mouse is still available but everything else (dock, finder, everyth

  • Visual Basic 6.0 Portable UAC?

    Aloha, II hhahavhavee received a copy of Microsoft Visual Basic 6 Portable. I noticed that the program has the UAC shield on it. What is going to happen that will change anything to the computer; if nothing, just what will it do? Please note: It is r