Java Unsigned Number Create unsignedLong(byte b)

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

Description

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

License

Open Source License

Parameter

Parameter Description
b the byte to convert.

Return

An unsigned long representing the specified byte.

Declaration

public static long unsignedLong(byte b) 

Method Source Code

//package com.java2s;
/*/* www.  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 long.
     * <p>
     * This converts the specified byte into a long. The least significant byte (8
     * bits) of the long will be identical to the byte (8 bits) provided, and the
     * most significant 7 bytes (56 bits) of the long 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 long representing the specified byte.
     */
    public static long unsignedLong(byte b) {
        return 0x00000000000000ff & b;
    }

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

    /**
     * Get the specified int's value as an unsigned long.
     * <p>
     * This converts the specified int into a long. The least significant int (32
     * bits) of the long will be identical to the int (32 bits) provided, and the
     * most significant int (32 bits) of the long will be zero.
     *
     * @param i the int to convert.
     * @return An unsigned long representing the specified int.
     */
    public static long unsignedLong(int i) {
        return 0x00000000ffffffff & i;
    }
}

Related

  1. unsignedIntValue(byte[] data, int offset)
  2. unsignedLeb128Size(int value)
  3. unsignedLessThan(long a, long b)
  4. unsignedLocalIntersect2by2(final short[] set1, final int length1, final short[] set2, final int length2, final short[] buffer)
  5. unsignedLocalIntersect2by2Cardinality(final short[] set1, final int length1, final short[] set2, final int length2)
  6. unsignedLongToByteArray(final long value)
  7. unsignedLongToString(long value)
  8. unsignedLongToString(long x)
  9. unsignedMediumToBytes(final Long unsignedInt)