Trouble with double byte swapping routine

I'm working on a program that reads little endian doubles from a DataInputStream and then swaps them. Usually, everything works fine. However, certain values don't swap correctly.
I'm at a total loss as to why this is happening, so I hoped one of you guys could show me. I've included a demonstration program with the method I'm using to swap doubles.
public class SwapTest
     public static void main(String[] args)
          new SwapTest();
     public SwapTest()
          // The swap routine works well with this value
          double d = 0.8660252094218776d;
          System.out.println("d before being swapped: " + d);
          // Swap to small order, then back to big order
          d = swapBytes(d);
          d = swapBytes(d);
          System.out.println("d after being swapped: " + d);
          System.out.println();
          // Everything gets totally hosed with this value
          d = 0.8660252079425844d;
          System.out.println("d before being swapped: " + d);
          // Swap to small order, then back to big order
          d = swapBytes(d);
          d = swapBytes(d);
          System.out.println("d after being swapped: " + d);
     private static double swapBytes(double sm)
          long smallendian = Double.doubleToLongBits(sm);
          long result;
          long l1 = (smallendian & 0x00000000000000FFL) << 56;
          long l2 = (smallendian & 0x000000000000FF00L) << 40;
          long l3 = (smallendian & 0x0000000000FF0000L) << 24;
          long l4 = (smallendian & 0x00000000FF000000L) << 8;
          long l5 = (smallendian & 0x000000FF00000000L) >>> 8;
          long l6 = (smallendian & 0x0000FF0000000000L) >>> 24;
          long l7 = (smallendian & 0x00FF000000000000L) >>> 40;
          long l8 = (smallendian & 0xFF00000000000000L) >>> 56;
          result = l1 | l2 | l3 | l4 | l5 | l6 | l7 | l8;
          return Double.longBitsToDouble(result);
}

The doubleToLongBits() method converts invalid values to NAN before converting

Similar Messages

  • Having trouble with double entries in ical after installing Lion.  After entering an event, another one pops up right next to it.

    Having trouble with double entries in ical after installing Lion.  After entering an event, another one pops up right next to it.

    Check iCal preferences, the Accounts Tab. You might have duplicate accounts.

  • Crystal XI R2 exporting issues with double-byte character sets

    NOTE: I have also posted this in the Business Objects General section with no resolution, so I figured I would try this forum as well.
    We are using Crystal Reports XI Release 2 (version 11.5.0.313).
    We have an application that can be run using multiple cultures/languages, chosen at login time. We have discovered an issue when exporting a Crystal report from our application while using a double-byte character set (Korean, Japanese).
    The original text when viewed through our application in the Crystal preview window looks correct:
    性能 著概要
    When exported to Microsoft Word, it also looks correct. However, when we export to PDF or even RPT, the characters are not being converted. The double-byte characters are rendered as boxes instead. It seems that the PDF and RPT exports are somehow not making use of the linked fonts Windows provides for double-byte character sets. This same behavior is exhibited when exporting a PDF from the Crystal report designer environment. We are using Tahoma, a TrueType font, in our report.
    I did discover some new behavior that may or may not have any bearing on this issue. When a text field containing double-byte characters is just sitting on the report in the report designer, the box characters are displayed where the Korean characters should be. However, when I double click on the text field to edit the text, the Korean characters suddenly appear, replacing the boxes. And when I exit edit mode of the text field, the boxes are back. And they remain this way when exported, whether from inside the design environment or outside it.
    Has anyone seen this behavior? Is SAP/Business Objects/Crystal aware of this? Is there a fix available? Any insights would be welcomed.
    Thanks,
    Jeff

    Hi Jef
    I searched on the forums and got the following information:
    1) If font linking is enabled on your device, you can examine the registry by enumerating the subkeys of the registry key at HKEY_LOCAL_MACHINEu2013\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink to determine the mappings of linked fonts to base fonts. You can add links by using Regedit to create additional subkeys. Once you have located the registry key that has just been mentioned, from the Edit menu, Highlight the font face name of the font you want to link to and then from the Edit menu, click Modify. On a new line in the dialog field "Value data" of the Edit Multi-String dialog box, enter "path and file to link to," "face name of the font to link".u201D
    2) "Fonts in general, especially TrueType and OpenType, are u201CUnicodeu201D.
    Since you are using a 'true type' font, it may be an Unicode type already.However,if Bud's suggestion works then nothing better than that.
    Also, could you please check the output from crystal designer with different version of pdf than the current one?
    Meanwhile, I will look out for any additional/suitable information on this issue.

  • BC4J with Double Byte

    Is it possible that I can create BC4J to access a 8i with ISO8859-1 characterSet, and show double byte information
    (ex:Chinese/Japaness) correctly in my applet? (ex:GridControl) So far I can only show Chinese correctly in my BC4J,
    when the 8i with a ZH16BIG5 character Set.
    Thanks for any idea. : )

    The doubleToLongBits() method converts invalid values to NAN before converting

  • Trouble with double

    Hi all,
    I tried to compile and run this code :
    public class TestDouble {
         public static void main(String ar[]) {
              //The total balance
              double balance =19620.9d;
            balance -= 3542.9d;
            //Expecting the balance to be 16078
              System.out.println("Remaining balance : "+balance);
              balance -= 6144.0d;
              //Expecting the balance to be 9934
              System.out.println("Remaining balance : "+balance);
              balance -= 1200.0d;
              //Expecting the balance to be 8734
              System.out.println("Remaining balance : "+balance);
              balance -= 1200.0d;
              //Expecting the balance to be 7534
              System.out.println("Remaining balance : "+balance);
              balance -= 5134.0d;
              //Expecting the balance to be 2400
              System.out.println("Remaining balance : "+balance);
              balance -= 1200.0d;
              //Expecting the balance to be 1200
              System.out.println("Remaining balance : "+balance);
              balance -= 1200.0d;
              //Expecting the balance to be 0
              System.out.println("Remaining balance : "+balance);
              System.out.println("Remaining balance > 0 : "+(balance>0));
    }I expect the final balance to be printed as zero.
    However this is the out put that I am getting
    G:\Ws\Test>javac -version
    javac 1.6.0_14
    G:\Ws\Test>javac G:\Ws\Test\TestDouble.java
    G:\Ws\Test>java -version
    java version "1.6.0_15"
    Java(TM) SE Runtime Environment (build 1.6.0_15-b03)
    Java HotSpot(TM) Client VM (build 14.1-b02, mixed mode, sharing)
    G:\Ws\Test>java TestDouble
    Remaining balance : 16078.000000000002
    Remaining balance : 9934.000000000002
    Remaining balance : 8734.000000000002
    Remaining balance : 7534.000000000002
    Remaining balance : 2400.000000000002
    Remaining balance : 1200.0000000000018
    Remaining balance : 1.8189894035458565E-12
    Remaining balance > 0 : trueCan someone help me in understanding what's wrong.
    Thanks,
    Anil

    For accounting, the thought of using rounding is not acceptable. Accounting typical only requires add, substract and multiplied by a quantity. An alternative to BigDecimal is to use long values for the smallest unit. e.g. use cents instead of dollars. The risk of error is important and BigDecimal is likely to be the best choice for this reason.
    However in finance or banking, rounding is better understood as it is used, often unavoidable. You will find double is typically used for simplicity (often speed is also given as justification) While double is dramatically faster than BigDecimal, this speed improvement is usually not required IMHO.
    Only large amounts of money are likely to have a significant rounding error, however large amounts of money are typically estimates. The problem with double is its limited precision, however money is a limit resource and very rare do you need more than 12 digits of accuracy. (double has 15-16 digits of accuracy) Even the US national debt can be represented to the cent using double, yet this is just an estimate. If you attempted to add up all the amounts involved in the US national debt, it would change while you are doing it.
    I worked at a bank where in one dept the unexplained PnL was measuring in "millions of pounds per month" (PnL being Profit and Loss) I can assure you if you has mentioned an error 1.8e-12 dollars it would be given a proportionate amount of consideration, if not amusement.
    In summary: There is no realistic, hard amount of money that would get an error using double which could not be handled by appropriate rounding. Any estimate of money is not accurate enough to require more precision than double.
    Edited by: Peter__Lawrey on 13-Dec-2009 14:38

  • Officejet Pro 8600 plus: trouble with double sided printing

    I have just installed Officejet Pro 8600 plus. My iMac is running on OS X 10.9.2
    I want to print a double sided brochure. And I have succeeded. However, the printing on one side of the paper is upside down.
    To achieve this:
    Print <Copies & Pages <Layout - turn on two-sided - long edge binding
    Layout direction is greyed out
    How can I fix this please

    Hello xxzz,
    Welcome to the HP Forums.
    I see that the flip on long edge option is greyed out for you when you try to print double sided. I will try to help you with this.
    Usually if an option is greyed out, it indicates that the software wasn't installed completely or correctly. That or the printer isn't capable of the task. Knowing that this printer is able to duplex, it could be a problem with the software/drivers.
    Try the following.
    Uninstall the software.
    Reset the print system.
    Verify/Repair disk permissions
    Re-install the software - software download
    Test to see if you're now able to choose the options.
    Let me know how things go, thank you for posting on the HP Forums.
    I worked on behalf of HP.

  • Trouble with doubles (adding, setting precision)

    Firstly,
    I have a loop that adds 0.3 three times. For some reason it comes out as .8999999999999!
    Why is this?
    Second, does anyone know where I can download a class or view source code that allows you to set decimal precision of a double? I started writing one myself but it's more complex than I thought and I'd rather just use someone elses if I could...

    The precision of calculations and how numerical
    floating point numbers are handled in computers are is
    very relevant for business situations. Actually the
    problems with decimal numbers themselves often need to
    be understood by those creating the business rules (ie
    like the sales people, audit departements, CEOs, etc.)
    The precision of the java double itself is unlikely to
    ever have an impact on that though.
    For example, if a business person asks you to
    calculate a mortgage payement then they must
    understand exactly the impact that the imprecision of
    such decimal calculations will have on the business.
    And they must understand it enough so that they can
    decide the correct way for handling it. The rules
    for handling this case, at least in the
    mortgage/banking industry, is going to be far less
    the possible precision that a java double can have.
    (The reason of course being that how this is handled
    d impacts the credits of the lender and the debits of
    the lendee.)
    Given the above it matters little what data types are
    used to handle the calculation itself. But rather
    that the calculation is done in such a way that the
    business people understand it and that they understand
    the limitations of it as well.Okay, I don't disagree with any of that. Still not sure about your overall point though.
    * P-L said "don't add doubles in a loop because it compounds rounding errors."
    * I said "but if the number of addtions multiplied by the maximum error is still within your error tolerance, it's okay." In other words, Java's double's precision is not necessarily going to be a problem.
    * You said some things that seem to agree with that final point, but your "that is fine if your job consists of nothing but evaluating computers, but for the rest of us the errors in the data that we are using..." comment makes it sound like you're disagreeing with my point: "The errors in Java's double may not cause you problems. Know it's limitations, and how they relate to your requirements."
    Are you looking for an argument, now that "one exit point" has fizzled? :-) Or am I just being particularly dense today?
    &para;

  • Sapshcut and  double-byte characters trouble?

    Hi experts,
    I did try some commands to log-on to SAP system as the following examples and get some conclusions:
    (1) sapshcut.exe -sysname="今ウィ ちゃわ異"  -user="paragon1"  -pw="paragon1"  -client="800" -language=en  -maxgui "
    (2) sapshcut.exe -sysname="EC5"  -user="paragon1"  -pw="paragon1"  -client="800" -language=en  -maxgui "
    - For the (1) case, with any "double-byte characters" sysname (Janpanese,...), I can not log-on to SAP and get "Microsoft Visual C++ Runtime Library" error message.
    - For the (2) case, without "double-byte characters" sysname, I can log-on to SAP easily.
    Thus, I wan to know
    1) Does the sapshcut.exe support double-byte characters?
    2) Do we have a way to use sapshcut.exe with double-byte characters(Japanese,...)?
    Kindly Regards,

    The comments on the bytes/strings were helpful. Thanks.
    But I'm still confused as to what matching pattern could be used.
    For example a pattern like:
    [A-Za-z]
    I assume would not match any double byte characters.
    I also assume the following won't work either:
    [\\p{Alpah}]
    because it is posix - US-ASCII only.
    So how do you say "match the tag, then take any characters,
    double byte, ascii, whatever, then match the text tag - per the
    original example ?

  • JSF and Double Byte Character

    Hi,
    I wanted to know how to handle <h:outputText> with chinese character or double byte character.
    See sample code below :
    <%@ page language="java" contentType="text/html; charset=UTF-8"      pageEncoding="UTF-8"%>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <h:form styleClass="form" id="form1">
    <% request.setCharacterEncoding("UTF-8"); %>
    <h:inputText styleClass="inputText" id="text1"></h:inputText>
    <hx:commandExButton type="submit" value="Submit" styleClass="commandExButton" id="button1"      action="#{pc_SubmitTest.doButton1Action}"></hx:commandExButton>
    <h:outputText styleClass="outputText" id="text2"></h:outputText>
    </h:form>
    When you input with double byte character and submit,
    the output screen value did not render properly .
    I tried this similiar code at JSP, it work fine.
    Anybody know how to solve this problem ?
    Anything need to do at pagecode level ?
    Thank you.
    Reinardy

    Problem was due to the fact that I was trying to generate the excel file in char stream instead of byte stream

  • Form English Char ( Single Byte  ) TO Double Byte ( Japanese Char )

    Hello EveryOne !!!!
    I need Help !!
    I am new to Java ,.... I got assignment where i need to Check the String , if that string Contains Any Non Japanse Character ( a~z , A~Z , 0 -9 ) then this should be replaced with Double Byte ( Japanese Char )...
    I am using Java 1.2 ..
    Please guide me ...
    thanks and regards
    Maruti Chavan

    hello ..
    as you all asked Detail requirement here i an pasting C code where 'a' is passed as input character ..after process it is giving me Double Byte Japanese "A" .. i want this to be Done ..using this i am able to Convert APLHA-Numeric from singale byte to Doubel Byte ( Japanse ) ...
    Same program i want to Java ... so pleas guide me ..
    #include <stdio.h>
    int main( int argc, char *argv[] )
    char c[2];
    char d[3];
    strcpy( c, "a" ); // a is input char
    d[0] = 0xa3;
    d[1] = c[0] + 0x80;
    printf( ":%s:\n", c ); // Orginal Single byte char
    printf( ":%s:\n", d ); // Converted Double Byte ..
    please ..
    thax and regards
    Maruti Chavan

  • Double byte characters turn into squares at PDF export use Unicode font

    Hi all,
    We developing with Visual Studio 2008, .NET 2.0 and Crystal Report XI Release 2 SP5 an international windows application. We use the font Arial Unicode MS in the rpt file. We translate the fix texts with the Crystal Translator (3.2.2.299).
    On the distributed installation of our software, the printout and preview displays the double byte characters properly (Japanese, Korean, Chinese), but when we export the report as PDF, the characters get displayed with squares. This happens also, when the font Arial Unicode MS is installed on the distributed installation on Windows XP Professional.
    I searched for hours for a solution in the knowlegde base articles and in forum of Crystal Report. I found one thread, which describes exactly our problem:
    [Crystal XI R2 exporting issues with double-byte character sets|Crystal XI R2 exporting issues with double-byte character sets;
    But we already introduced the solution to use Unicode font and I also linked the font Lucida Sans Unicode to the Arial Unicode MS, but we still face the problem.
    Due to our release on thursday we are very under pressure to solve this problem asap.
    We appreciate your help very much!
    Ronny

    Your searches should have also come up with the fact that CR XI R2 is not supported in .NET 2008. Only CR 2008 (12.x) and Crystal Reports Basic for Visual Studio 2008 (10.5) are supported in .NET 2008. I realize this is not good news given the release time line, but support or non support of cr xi r2 in .net 2008 is well documented - from [Supported Platforms|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/7081b21c-911e-2b10-678e-fe062159b453
    ] to [KBases|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_dev/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes.do], to [Wiki|https://wiki.sdn.sap.com/wiki/display/BOBJ/WhichCrystalReportsassemblyversionsaresupportedinwhichversionsofVisualStudio+.NET].
    Best I can suggest is to try SP6:
    https://smpdl.sap-ag.de/~sapidp/012002523100015859952009E/crxir2win_sp6.exe
    MSM:
    https://smpdl.sap-ag.de/~sapidp/012002523100000634042010E/crxir2sp6_net_mm.zip
    MSI:
    https://smpdl.sap-ag.de/~sapidp/012002523100000633302010E/crxir2sp6_net_si.zip
    Failing that, you will have to move to a supported environment...
    Ludek
    Follow us on Twitter http://twitter.com/SAPCRNetSup
    Edited by: Ludek Uher on Jul 20, 2010 7:54 AM

  • Double byte stream name

    Hi,
    is it possible to play RTMP stream with double byte name like japanese korean etc.. ?
    I tried to with and without escape() stream name without success
    lke "rtmp://server.com:1935/app/"+escape(streamName)
    doesn't work
    thanks
    Franck

    I tried it out, and I am able to play RTMP stream with double byte character as stream name, in both vod and live.
    What stream name are you giving? Can you explain a bit further the steps you are following.

  • How to display double byte characters with system.out.print?

    Hi, I'm a newbie java programmer having trouble to utilize java locale with system io on dos console mode.
    Platform is winxp, jvm1.5,
    File structure is:
    C:\myProg <-root
    C:\myProg\test <-package
    C:\myProg\test\Run.java
    C:\myProg\test\MessageBundle.properties <- default properties
    C:\myProg\test\MessageBundle_zh_HK.properties <- localed properties (written in notepad and save as Unicode, window notepad contains BOM)
    inside MessageBundle.properties:
    test = Hello
    inside Message_zh_HK.properties:
    test = &#21890; //hello in big5 encoding
    run.java:
    package test;
    import java.util.*;
    public class Run{
      public static void main(String[] args){
        Locale locale = new Locale("zh","HK");
        ResourceBundle resource =
            ResourceBundle.getbundle("test.MessageBundle", locale);
        System.out.println(resource.getString("test"));
      }//main
    }//classwhen run this program, it'll kept diplay "hello" instead of the encoded character...
    then when i try run the native2ascii tool against MessageBundle_zh_HK.properties, it starts to display monster characters instead.
    Trying to figure out what I did wrong and how to display double byte characters on console.
    Thank you.
    p.s: while googling, some said dos can only can display ASCII. To demonstrate the dos console is capable of displaying double byte characters, i wrote another helloWorld in chinese using notepad with C# and compile using "csc hello.cs", sure enough, console.write in c# allowed me to display the character I was expecting. Since dos console can print double byte characters, I must be missing something important in this java program.

    after google a brunch, I learned that javac (hence java.exe) does not support BOM (byte order mark).
    I had to use a diff editor to save my text file as unicode without BOM in order for native2ascii to convert into a ascii file.
    Even the property file is in ascii format, I'm still having trouble to display those character in dos console. In fact, I just noticed I can use system.out.println to display double byte character if I embedded the character itself in java source file:
    public class Run {
         public static void main(String[] args) throws UnsupportedEncodingException{
              String msg = "&#20013;&#25991;";    //double byte character
                    try{
                    System.out.println(new String(msg.getBytes("UTF-8")) + " new string");  //this displays fine
                    catch(Exception e){}
                    Locale locale = new Locale("zh", "HK");
              ResourceBundle resource = ResourceBundle.getBundle("test.MessagesBundle", locale);
                    System.out.println(resource.getString("Hey"));      //this will display weird characterso it seems like to me that I must did something wrong in the process of creating properties file from unicode text file...

  • I am having trouble with my iphoto. I can't print from there or do much of anything. When i double click on an event it doesnt open. Any suggestions?

    I am having trouble with my iphoto. I can't print from there or do much of anything. When i double click on an event it doesnt open. Any suggestions?

    ~/Library/Preferences/com.apple.iPhoto.plist
    ~ = your home folder
    Here's a picture
    Chris

  • I have a factory unlocked 4s I'm haveing trouble with the mms withI have a  straight talk I'm useing the sim card swap with tmoblil sim card I'm following the insructions but it works for a while and then its gone. I've set the settings at least ten times

    I have a factory unlocked 4s I'm having trouble with the mms with straight talk I've been useing the sim swap system with tmobile i have put the settings in five times. The setting won't stay it works for a while and then it's gone. I'm not in a good coverage area but when i put the settings in i make sure i'm getting a good signal or near wifi. any suggestions would be great.

        Congrats on your recent upgrade actionkatie! I am sorry to learn of the difficulties you are experiencing with your Samsung Galaxy S4. Let's get to the bottom of this because we want you to love your phone.
    I understand you have done all necessary troubleshooting steps that should have enabled you to send messages to iPhone users without them having to disable iMessage. Have you tried contacting Apple Support regarding the inability to send a text message to iPhone users? Apple can be reached at (800) 275-2273.
    In addition, do you get a certain error message when your WiFi stops working? Have you verifed that Auto Switch network is disabled? To disable this setting simply to go Settings > Wi-Fi > Tap the Menu Key(to the left of the home button) > Select Advanced and it is called `Auto network switch. If you are still experiencing difficulties, please feel free to reach out to us for further assistance.
    Thank You,
    MichelleL_VZW
    VZW Support
    Follow us on Twitter @VZWSUPPORT

Maybe you are looking for