Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static final int FIFTH_BITMASK = 16;
    public static final int FIRST_BITMASK = 1;
    public static final int FORMAT_FLOAT = 52;
    public static final int FORMAT_SFLOAT = 50;
    public static final int FOURTH_BITMASK = 8;
    public static final int SECOND_BITMASK = 2;
    public static final int THIRD_BITMASK = 4;

    public static Float getFloatValue(byte[] value, int format, int position) {
        if (value == null || (format & 15) + position > value.length) {
            return null;
        }
        switch (format) {
        case FORMAT_SFLOAT /*50*/:
            int i = value[position + FIRST_BITMASK];
            return Float.valueOf(
                    (float) (((double) signed((value[position] & 255) + (((i & 255) & 15) << FOURTH_BITMASK), 12))
                            * Math.pow(10.0d, (double) signed((i & 255) >> THIRD_BITMASK, THIRD_BITMASK))));
        case FORMAT_FLOAT /*52*/:
            int exponent = value[position + 3];
            int mantissa = value[position + SECOND_BITMASK];
            return Float.valueOf((float) (((double) signed(
                    ((value[position] & 255) + ((value[position + FIRST_BITMASK] & 255) << FOURTH_BITMASK))
                            + ((mantissa & 255) << FIFTH_BITMASK),
                    24)) * Math.pow(10.0d, (double) exponent)));
        default:
            return null;
        }
    }

    private static int signed(int value, int length) {
        if (((FIRST_BITMASK << (length - 1)) & value) != 0) {
            return ((FIRST_BITMASK << (length - 1)) - (((FIRST_BITMASK << (length - 1)) - 1) & value)) * -1;
        }
        return value;
    }
}