Base Conversion - Negative Base

Hello everybody. I am writing a code of Base Conversion. I came to know that there are [Negative base|http://en.wikipedia.org/wiki/Negative_base] too. And I am able to convert fractional number with negative base into decimal and in that link there is an algorithm given to convert decimal to number with negative base, but they all are in integers. If anyone know the procedure/algorithm of converting a fractional decimal number, please let me know, it will be very helpful to me. Thank you.
I am posting the toDecimal() method, however there are other methods too :
public String toDecimal(String numberInInputBase, String inputBase) throws ParseError {
          this.numberInInputBase = numberInInputBase;
          if (inputBase.equals("0") || inputBase.equals("1")) {
               throw new ParseError("Invalid input");
          this.inputBase = inputBase;
          this.lookUpStringForInputBase = lookUpString.substring(0, Math.abs(Integer.parseInt(inputBase)));
          split();
          return toDecimal();
     public String toDecimal() throws ParseError {
          // if the numberInInputBase or inputBase is vacent
          if (numberInInputBase == null || inputBase == null) {
               throw new ParseError("Invalid input");
          BigDecimal output = new BigDecimal(BigInteger.ZERO); // initialize output
          BigDecimal base = new BigDecimal(inputBase); // convert inputBase into BigDecimal
          for (int idx = 0; idx < intPart.length(); idx++) {
               int digit = lookUpStringForInputBase.indexOf(intPart.charAt(idx));
               // intPart.charAt(idx) return charater at a perticular idx and then lookUpStringForInputBase.indexOf return
               // the index of that character
               if (digit != -1) {
                    // if character is found in the String
                    output = output.add(BigDecimal.valueOf(digit).multiply(base.pow(intPartLength--)));
               } else {
                    throw new ParseError("Invalid input");
          if (fracPartLength != 0) {
               int incr = 0;
               for (int idx = 0; idx <= fracPartLength; idx++) {
                    int digit = lookUpStringForInputBase.indexOf(fracPart.charAt(idx));
                    if (digit != -1) {
                         output = output.add(BigDecimal.valueOf(digit).divide(base.pow(++incr), 10, BigDecimal.ROUND_HALF_UP));
                    } else {
                         throw new ParseError("Invalid input");
          this.numberInOutputBase = output.toString();
          return getNumberInOutputBase();
     }Edited by: tapas.23571113 on Aug 2, 2010 4:32 AM

Hi,
Read the javadoc for Integer. There are two methods which you are interested in, parseInt(String s, int radix) and toString(int i, int radix)
Kaj

Similar Messages

  • Base method and base value

    Dear forum,
    I would like to seek advice on the above.
    I do not sure what is the difference between base method and base value in multilevel method.
    What is the difference between these 2 base?
    Thanks

    Hi,
    If you go ti AFAMA nd chosse a depr, key you can see the base Method as one component of the key.
    Here is defined:
    - Type of depreciation
    - Dep. method and
    - Treatment of end of depreciaion
    If you take a look at the "multilevel method (also in AFAMA) you can see the base value.
    The value used as the basis for the calculation of depreciation.
    Regards Bernhard

  • Base Currency Or Base Amount Does Not Have a Value?

    Hi
    I've received the following error on the PRC: Distribute Borrowed and Lent Amounts process: Base Currency Or Base Amount Does Not Have a Value
    Does anyone know what it means?

    Hi
    Do you have different currencies for your provider and receiver operating units?
    Is there a difference between the transaction currency Ithe expenditure item) and the receiving OU currency?
    Verify daily exchange rates exists for the relevant transaction dates.
    Dina

  • What's the difference between XI basis and regular basis?

    I am an SAP basis admin for years.
    Now my corp starts to use XI.
    What is the difference between XI basis and regular basis if there is any?
    Thanks!

    Hi,
    No difference... Basis is Basis (Technical consultant)... According to me its just terminology changed. i.e. SAP Administrator instead of SAP basis.
    For XI you may need to additionally control the Java stack administartion along with ABAP stack.
    Please go thourgh the below link to know about SAP NetWeaver Administrator, then you may compare with regular Basis activities
    http://help.sap.com/saphelp_nw70/helpdata/en/7e/c82c42be6fde2ce10000000a1550b0/frameset.htm
    Also
    Refer - PI/XI administartion study material links
    PI Administration, monitoring document
    Thanks
    Swarup

  • Cisco 4900 switch LAN base to IP base IOS upgrade

    Hi,
    I have purchased WS-C4900-SW-LIC= for upgrading 4900 switch from LAN base to IP base IOS.
    I have not received any PAK or installable license file. Only license agreement is provided by CIsco.
    While upgrading do I need to install license file on switch?
    Regards,
    Andy

    Anderson,
    Contact the licensing team and request for an update using your PO/SO since you have not received the PAK.
    Link:  https://tools.cisco.com/SWIFT/LicensingUI/Home
    Indeed we need to install the license file on the switch
    First copy this license to the switch's flash memory using the copy command
    and a TFTP server.
    Note, while the dir bootflash: command now lists the file in the bootflash, it has
    not yet been installed. The license install command must be used to install
    the license.
    Example:
    4948# license install flash:license_name-ips
    Please issue the following command and then reload the switch.
    4948(config)#license boot  level ipservices
    4948(config)#end
    4948L# wr
    4948# reload
    Haihua

  • Cash Basis and Accrual Basis Profit & Loss Statement

    Dear Experts
    can we generate Cash basis and accrual basis Profit and loss statement ? if possible then let me know how can we do in SAP Business one 8.8
    Regards
    Rajani PAtel

    Dear Rajani,
    B1 has no supports for the statement you need. You have to create your own report.
    Thanks,
    Gordon

  • Downgrade 3750X w/ IP Base to LAN Base for Stacking

    I have a WS-C3750X-12S-S (IP Services) that I THINK I'd like to downgrade to LAN Base so I can stack it with a WS-C3750X-48T-L that is already LAN Base...
    Can I do this?  Any reasons I shouldn't?  Small environment, isn't much routing at all going on here...Thanks!       

    That is because it is not an image it is a license.
    However you will loose more than just routing abilities.
    so if i where you i would go the other way.
    I would buy a license upgrade to upgrade the Lan base to ip base instead.
    otherwise you will loose alot of functionality that you might want/need such as eem, powerstacking and so on.
    to buy a license to upgrade contact your local cisco rep.
    to change to a license from ip base to Lan base contact cisco licensing
    [email protected]
    good luck
    HTH

  • Conversion of Base units

    Hello BPC Gurus,
    Is there any posibility to convert Base Units in BPC 7.5 Nw version? For example I have base units in Kg,Pieces,Liters . If I want to convert Kg into liters or Liters Into KG or Liters into pieces or vice versa.
    I have  heard that we have to use ABAP programming for conversion of above stated Base units(Kg,Pieces,Liters). Please let me know how to use ABAP Programming in BPC.
    Thanks in advance.
    With regards,
    Anand Kumar

    Hi Anand,
    You can convert units of measure using script logic or a script logic BADI (ABAP). For lots of examples of BADIs, you can look at the BPC NW How-To guides on the SDN wiki.
    You could also conceivably use the currency conversion functionality of BPC to manage conversion of units of measure but it is not really optimized for that use case and you would probably need to choose to use if for either UoM conversion or currency conversion. Using the currency conversion for both purposes is very problematic.
    Ethan

  • SOP:   MA-501 conversion into base unit error

    Dear All
    I am using flexible planning and at the time of transfer to Demand Management through MC90 i am facing the following Express document error
    Update was terminated
    Update key...   C96200E1E440F1798829001A64D28E46
    Generated....   27.10.2011, 11:14:32
    Completed....   27.10.2011, 11:14:33
    Error Info...   MA 501: Not possible to convert from TO
    However the Base unit of Measure of my Material is TO - Tonne and InfoStructure unit is also TO. I am unable to understand if Base unit of measure is same as planning unit, why system is throwing conversion error in express document.
    Kindly help me out in solving this problem.
    Regards

    Hi,
    Please check
    1) The Base unit of measure maintained for the info strucuture in MC7F. If that is matching with material master then check the unit for the key figure in MC23 as per SAP Note 95132.
    2) If the unit of measure in MC7F for the info structure is different then try to maintain alternative unit of measure concept in the material master.
    Regards
    Brahmaji D

  • Capacity Leveling - wrong conversion of base quantity

    Hello Everyone,
    we have the following issue /question with respect to capactiy leveling using PDS (APO 5.0):
    the base unit conversion  does not seem to be correct in the capacity leveling view:
    Our settings:
    In our routing we have defined a base qty of 10 PC, no break, no set up time, only 2min. machine no labour.
    Resource: Single mixed , 100% capacity consumption
    Material Output BOM =100 PC
    PDS activity conversion for 100 PC = 1200 seconds
    However: when entering 100 PC as planned requirement, the system calculates a capacity consumption of 33,33 hrs, with 10 PC 3,33, 1 PC 0,33 hrs. not the expected 20 minutes. Can anyone help clearing the fog? Any setting missing?
    Thanks a lot,
    Toms Team

    Hi Dibyendu,
    In both the material order unit is not maintained.
    Only the base unit of measure is maintained as EA and in additional data under units of measure the conversion  factor of 1EA = 2 KG is maintained for both materials

  • How do I make conversions between bases

    Hi, does someone know how to make conversion with the bases of the numbers. I need to convert any number from the decimal bases, to binary, or hexagesimal, or from any of the bases mentioned to the decimal base.

    Have a look at the Integer class.

  • 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.

  • Java Calculations base 8 or base 10?

    My colleague was told by out 'Java Experts' who are developers for a prominent Indian outsourcing company that all calculations are carried out in base 8 or is a number was multiple by 10 it will actually multiply the number by 8 as 10 (base 8) is 8 (base 10). So a simple currency conversion becomes either a multiple by 144 to make it pence from pounds. Is that correct? My colleague has deceived to simply move the decimal point by two places which needs more coding then a multiple. Please advice

    My colleague was told by out 'Java Experts' who are developers for a
    prominent Indian outsourcing company that all calculations are
    carried out in base 8 or is a number was multiple by 10 it will actually
    multiply the number by 8 as 10 (base 8) is 8 (base 10). So a simple
    currency conversion becomes either a multiple by 144 to make it
    pence from pounds. Is that correct? My colleague has deceived to
    simply move the decimal point by two places which needs more
    coding then a multiple. Please adviceIt isn't April's fool day yet but your colleague has been tricked already ;-)
    Or did he speak to some 'manager' by accident?
    kind regards,
    Jos (*giggle*)

  • Mac Mini will no longer recognize Apple extreme base as a base. HELP

    I have a 2004 apple extreme base station that after a brief power outage would not work. the only thing I could do to get wireless to work was reboot (pushed on the button in the back for 5 seconds).  my computer now recognizes the wireless but it has been reset back to Apple ### and will not recognize it as a base station under the wireless options or in the Wireless Utility.
    How do I make my computer recognize the airport as a base station again so I can password protect my network?

    The main problem here is that you will need to use....or borrow..... a Mac that is running the Leopard or Snow Leopard operating system to be able to "see" the older AirPort that you have. A PC might work as well.
    Macs running Lion, Mountain Lion, and Mavericks cannot be used to configure the older AirPort that you have.
    Five years is considered good service for a router, and you have seen ten. You are way ahead of the game.
    It is likely time to think about a new AirPort Extreme that will be compatible with the newer Mac operating systems. AirPort Utility on the iPhone and iPad will work on the new AirPort as well.

  • Partitioning on Oracle 8.0.6 (rule base vs. cost base)

    At my current engagement, we are using Oracle Financials 11.0.3 on Oracle 8.0.5 which uses rule-based optimizer. However, it is been planned to upgrade the database from Oracle 8.0.5 to Oracle 8.0.6 as well as implement Oracle partitioning. With this in mind, we are concerned about possible performance issues that the implementation of partitioning may cause since RBO does not recognize it.
    We agree that the RBO will see a non-partitioned table the same as a partitioned. In this scenario where you gain the most is with backup/recoverability and general maintenance of the partitioned table.
    Nevertheless, we have a few questions:
    When implementing partitions, will the optimizer choose to go with Cost base vs. Rule base for these partitioned tables?
    Is it possible that the optimizer might get confused with this?
    If this change form RBO to CBO does occur, the application could potential perform poorly because of the way it has been written.
    Please provide any feedback.
    thanks in advance.

    If the CBO is invoked when accessing these tables, you may run into problems.
    - You'll have to analyze your tables & ensure that the statistics are kept up to date.
    - It's possible that any SQL statements which invoke the CBO rather than the RBO will have different performance characteristics. The SYSTEM data dictionary tables, for example, must use the RBO or their performance suffers dramatically. Most of the time, the CBO beats the RBO, but applications which have been heavily tuned with the RBO may have problems with the CBO.
    - Check your init.ora to see what optimizer mode you're in. If you're set to CHOOSE, the CBO will be invoked whenever statistics are available on the table(s) involved. If you choose RULE, you'll only invoke the CBO when the RBO encounters situations it doesn't have rules for.
    Justin

Maybe you are looking for

  • How do you auto populate a date in a different text field after someone digitally signs the PDF form?

    I am trying to auto populate a date in a text box on the upper right hand corner of my document after someone digitally signs it. Is this possible? How do you do this?

  • QM01 - Equipment number

    Hi, This may be a config issue but I'm trying to help our Business Analyst sort out a problem. He has created a new Notification type Q7 and in config has set Screen Type Hdr = H500, Screen Type Object =  0100 (Functional Location + equipment +assemb

  • Two Bugs in Sysprep: No Win Updates and CopyProfile Copies Search Suggestions

    We are using Windows 8.1 Enterprise 64-bit with Update 1. I am not sure where (and even if) Microsoft accepts bug reports, but here are two that have been major annoyances for us for the past week.  They have workarounds, but they really need to just

  • Can you add menus to home movies?

    Hi, Just wondering if iMovie has any way of adding menus to the start of home movies. The sort of menu that you can select chapters from to jump to different sections of the movie.

  • BBM doesnt work just to one contact

    Both my brother and I have 8900 curves, adn we're on each other bbm list. I can send messages to anyone else on my list, and they go through fine, but if i ever send him a message, or he sends me one, whilst the tick has the small D above it, neither