Hi John:
 
I had the same problem with byte-ordering of floats: I could solve it by reading an integer and then converting it with the following method. If someone else has a better idea I would love to know.
 
--- Snippet ---
 
    // My files were written with Intel floats, so...
    private float convertBitsToFloat(int intelBits) {
       Float aFloat = new Float(0f);
       int javaBits = ((intelBits & 0xff000000) >> 24) +
                      ((intelBits & 0x00ff0000) >>  8) +
                      ((intelBits & 0x0000ff00) <<  8) +
                      ((intelBits & 0x000000ff) << 24);
       return aFloat.intBitsToFloat(javaBits);
    }
 
--- End snippet ---
 
Hope you can use it.
 
- Rudolf
 
 
----- Original Message -----
From: "Dickinson, John" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, January 05, 2000 17:52
Subject: [JAVA3D] reading binary data files

> I know I could post this to a general java list but the problem came up
> while looking at building a loader for STL files (used for faceted
> descriptions of 3D objects to be built using rapid prototyping processes).
>
> Questions:
> 1) though I have started building a loader for STL files if there is one
> already out there then please let me know!!
> I have searched through multiple archives of loaders with no luck.
> 2) I can load ascii STL file but binary ones (more common) are a bit of a
> problem due to byte ordering!
> e.g. my file has encoded in it the number 12 (in four bytes written by a
> C++/C program on a PC writting out an int)
> the binary coding looks like: 0C 00 00 00
> When using a DataStreamInput method readInt() gives me 201326592!
> What java expects is that the number 12 would be encoded as 00 00 00 0C
> instead!
>
> Though I can read these byte by byte and reconstruct integers manually I
> hate to think what I would have to do in order to read floats written by the
> same C program!
>
> Any suggestions, alternative apporaches?
> John
>
> --
> -((Insert standard disclaimer here))-|- Washington Irving (1783-1859) -
> John Kenneth Dickinson               |   "A sharp tongue is the only
> Research Council Officer  IMTI-NRC   |    edge tool that grows keener
> email:
[EMAIL PROTECTED]         |    with constant use."
>
> ===========================================================================
> To unsubscribe, send email to
[EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST".  For general help, send email to
>
[EMAIL PROTECTED] and include in the body of the message "help".
>
>

Reply via email to