Java Unsigned Number Create unsignedIntToLong(byte[] b)

Here you can find the source of unsignedIntToLong(byte[] b)

Description

Converts a 4 byte array of unsigned bytes to an long

License

Open Source License

Parameter

Parameter Description
b an array of 4 unsigned bytes

Return

a long representing the unsigned int

Declaration

public static long unsignedIntToLong(byte[] b) 

Method Source Code

//package com.java2s;
/* Penny Post - A postage system for email
 * Copyright (c) 2006-2007  Gregory Rubin <grrubin@gmail.com> 
 * http://www.nettgryppa.com // w ww  .j  a  v  a  2  s. c  om
*  Copyright (C) 2007  Aliasgar Lokhandwala <d7@freepgs.com> 
 * http://pennypost.sourceforge.net/
 * 
 * CashUtils.java: Provides common helper methods
 *
 * 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 {
    /**
     * Converts a 4 byte array of unsigned bytes to an long
     * 
     * @param b
     *            an array of 4 unsigned bytes
     * @return a long representing the unsigned int
     * 
     * @author Gregory Rubin
     */
    public static long unsignedIntToLong(byte[] b) {
        long l = 0;
        l |= b[0] & 0xFF;
        l <<= 8;
        l |= b[1] & 0xFF;
        l <<= 8;
        l |= b[2] & 0xFF;
        l <<= 8;
        l |= b[3] & 0xFF;
        return l;
    }
}

Related

  1. unsignedIntersect2by2(final short[] set1, final int length1, final short[] set2, final int length2, final short[] buffer)
  2. unsignedIntersects(short[] set1, int length1, short[] set2, int length2)
  3. unsignedIntToByteArray(long value)
  4. unsignedIntToHex(int i)
  5. unsignedIntToInt(byte[] b)
  6. unsignedIntToLong(byte[] b)
  7. unsignedIntToLong(byte[] bytes)
  8. unsignedIntToLong(byte[] source)
  9. unsignedIntToLong(int value)