Here you can find the source of swapInteger(int integer)
Parameter | Description |
---|---|
integer | the integer to swap |
public static int swapInteger(int integer)
//package com.java2s; /*/* w ww . j av a2 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 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) { int swapped = 0, byte1, byte2, byte3, byte4; byte1 = (integer >> 0) & 0xff; byte2 = (integer >> 8) & 0xff; byte3 = (integer >> 16) & 0xff; byte4 = (integer >> 24) & 0xff; swapped = byte1 << 24 | byte2 << 16 | byte3 << 8 | byte4 << 0; return swapped; } }