Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

converting Byte [] into float []

801494May 2 2010 — edited May 2 2010
Hi, I read the contents of a file into a byte array and am now trying to convert it into a float array.

here is the code I am using
public static float [] bytetofloat(byte [] convert){

    float [] data = new float [convert.length/2];
    for(int i = 0;i<convert.length;i+=2){
        for(int j = 0; j <data.length;j++){



        short valueAsShort = (short)( (convert[i] << 8)  | (convert[i+1] & 0xff));
        float valueAsFloat = (float)valueAsShort;
        System.out.println(valueAsFloat);
        valueAsFloat = data[j];
        System.out.println(data[j]);
         }
    }
can anyone see anythign wrong with the way I am doing this? I cant see anythign wrong but need to make sure its fine before I can continue.

any advice on this or a better way to do it would be much appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 30 2010
Added on May 2 2010
10 comments
515 views