Here you can find the source of createWord(final ByteOrder aByteOrder, final int aMSB, final int aLSB)
Parameter | Description |
---|---|
aMSB | the most significant byte; |
aLSB | the least significant byte. |
public static int createWord(final ByteOrder aByteOrder, final int aMSB, final int aLSB)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011, J.W. Janssen/*from ww w .j av a2 s . co m*/ * * 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. *******************************************************************************/ import java.nio.*; public class Main { /** * Creates a (16-bit) word value with the correct byte order. * * @param aMSB * the most significant byte; * @param aLSB * the least significant byte. * @return the 16-bit combination of both given bytes in the order of * endianness. */ public static int createWord(final ByteOrder aByteOrder, final int aMSB, final int aLSB) { if (aByteOrder == ByteOrder.BIG_ENDIAN) { return ((aMSB << 8) & 0xFF00) | (aLSB & 0x00FF); } return ((aLSB << 8) & 0xFF00) | (aMSB & 0x00FF); } /** * Creates a (16-bit) word value with the correct byte order. * * @param aMSB * the most significant byte; * @param aLSB * the least significant byte. * @return the 16-bit combination of both given bytes in the order of * endianness. */ public static int createWord(final int aMSB, final int aLSB) { return createWord(ByteOrder.nativeOrder(), aMSB, aLSB); } }