Java Number Swap swap16(final int aValue)

Here you can find the source of swap16(final int aValue)

Description

Switches the order of bytes of the given (16-bit) word value.

License

Open Source License

Parameter

Parameter Description
aValue the (16-bit) word value to switch the byte order for.

Return

the given value with the MSB & LSB switched.

Declaration

public static int swap16(final int aValue) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011, J.W. Janssen//from w w w.  j  ava  2  s  .  com
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     J.W. Janssen - Cleanup and make API more OO-oriented.
 *******************************************************************************/

public class Main {
    /**
     * Switches the order of bytes of the given (16-bit) word value.
     * <p>
     * In effect, this method casts a little-endian value to a big-endian value
     * and the other way around.
     * </p>
     * 
     * @param aValue
     *          the (16-bit) word value to switch the byte order for.
     * @return the given value with the MSB & LSB switched.
     */
    public static int swap16(final int aValue) {
        return (((aValue & 0x00ff) << 8) | ((aValue & 0xff00) >> 8));
    }
}

Related

  1. swap(short x)
  2. swap(String str, int i, int j)
  3. swap(StringBuffer s, int i, int j)
  4. swap(T a, T b)
  5. swap(T... args)
  6. swap16(short rgb)
  7. swap32(int rgb)
  8. swapAddresses(T o1, T o2)
  9. swapBits(byte in)