32 bit floating point decimal help

Posted on 2012-08-14
Last Modified: 2012-08-18
I've got a 32 bit floating point decimal at a device. It's split into two 16 bit integers to go over the wire.

The original value, at the device, is 156.

The two 16 bit integers come across as 17180 and 0. How do I convert, in C#, the 17180 and 0 back to 156?
Question by:lateapex
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    Use bitwise OR ( | ) combined with a left shift ( << ):

    int result = (int1 << 16) | int2;

    Open in new window

    be sure to put them in the correct order of higher-order bits and lower-order bits (higher on the left of the |).

    Author Comment

    So I tried this:

     int myFirst = 17180;
                int mySecond = 0;
                int myResult = myFirst | mySecond;

    myResult came out to 17180.

    I'm trying put the two back together to form a 32 bit floating point that I know left the device with a value of 156.

    The reason for this is the device sometimes reverses the order of the two 16 bit integers and we need to debug.

    LVL 74

    Accepted Solution

    I edited my post (not quick enough it seems). You need a left-shift as well. However, I don't see how you could possibly get back a number that is smaller than either of its two parts. I think something isn't correct in the initial conversion.

    Author Closing Comment

    Thanks for the help. I didn't ask a good question.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now