Java Number Swap swapFloat(float floatValue)

Here you can find the source of swapFloat(float floatValue)

Description

Byte-swaps the given float to the other endian.

License

Open Source License

Parameter

Parameter Description
floatValue the float to swap

Declaration

public static float swapFloat(float floatValue) 

Method Source Code

//package com.java2s;
/*//from ww w  .jav a  2 s  .co m
 * Copyright 1999-2002 Carnegie Mellon University.  
 * Portions Copyright 2002 Sun Microsystems, Inc.  
 * Portions Copyright 2002 Mitsubishi Electric Research Laboratories.
 * All Rights Reserved.  Use is subject to license terms.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 *
 */

public class Main {
    /**
     * Byte-swaps the given float to the other endian. That is, if this float is big-endian, it becomes little-endian,
     * and vice-versa.
     *
     * @param floatValue the float to swap
     */
    public static float swapFloat(float floatValue) {
        return Float.intBitsToFloat(swapInteger(Float
                .floatToRawIntBits(floatValue)));
    }

    /**
     * Byte-swaps the given integer to the other endian. That is, if this integer is big-endian, it becomes
     * little-endian, and vice-versa.
     *
     * @param integer the integer to swap
     */
    public static int swapInteger(int integer) {
        return (((0x000000ff & integer) << 24)
                | ((0x0000ff00 & integer) << 8)
                | ((0x00ff0000 & integer) >> 8) | ((0xff000000 & integer) >> 24));
    }
}

Related

  1. swapByte(byte b)
  2. swapBytes(final int i)
  3. swapCasing(String str)
  4. swapDouble(double value)
  5. swapDouble(double value)
  6. swapFloat(float value)
  7. swapInt(int i)
  8. swapInt(int i)
  9. swapInteger(int integer)