Java Unsigned Number Create unsignedShort(byte b)

Here you can find the source of unsignedShort(byte b)

Description

Get the specified byte's value as an unsigned short.

License

Open Source License

Parameter

Parameter Description
b the byte to convert.

Return

An unsigned short representing the specified byte.

Declaration

public static short unsignedShort(byte b) 

Method Source Code

//package com.java2s;
/*// w  w  w .j  a v  a 2s  .c  om
 * Copyright (C) 2014 Jesse Caulfield 
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Get the specified byte's value as an unsigned short.
     * <p>
     * This converts the specified byte into a short. The least significant byte
     * (8 bits) of the short will be identical to the byte (8 bits) provided, and
     * the most significant byte (8 bits) of the short will be zero.
     * <p>
     * For many of the values in this USB API, unsigned bytes are used. However,
     * since Java does not include unsigned bytes in the language, those unsigned
     * bytes must be converted to a larger storage type before being used in
     * unsigned calculations.
     *
     * @param b the byte to convert.
     * @return An unsigned short representing the specified byte.
     */
    public static short unsignedShort(byte b) {
        return (short) (0x00ff & b);
    }
}

Related

  1. unsignedLongToString(long value)
  2. unsignedLongToString(long x)
  3. unsignedMediumToBytes(final Long unsignedInt)
  4. unsignedNumericToByteArray(long src, int length)
  5. unsignedOneSidedGallopingIntersect2by2(final short[] smallSet, final int smallLength, final short[] largeSet, final int largeLength, final short[] buffer)
  6. unsignedShort(short s)
  7. unsignedShort2Arr(int var, byte[] arrayBytes, int startIndex)
  8. unsignedShortAt(byte[] data, int pos)
  9. unsignedShortBytesToInt(byte[] b)