Here you can find the source of swap16(final int aValue)
Parameter | Description |
---|---|
aValue | the (16-bit) word value to switch the byte order for. |
public static int swap16(final int aValue)
//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)); } }