Here you can find the source of bytes2int(byte[] bytes)
Parameter | Description |
---|---|
bytes | Array that will be converted |
public static int bytes2int(byte[] bytes)
//package com.java2s; /*/*from w w w . j a v a 2 s .c o m*/ * Copyright (c) 2014 Cisco Systems, Inc. and others. 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 */ public class Main { /** * Converts Byte Array into Integer value * * @param bytes Array that will be converted * @return Integer value of specified Array */ public static int bytes2int(byte[] bytes) { if (bytes == null) { return 0; } switch (bytes.length) { case 1: return bytes[0] & 0xFF; case 2: return (bytes[0] & 0xFF) << 8 | bytes[1] & 0xFF; case 3: return (bytes[0] & 0xFF) << 16 | (bytes[1] & 0xFF) << 8 | bytes[2] & 0xFF; case 4: return (bytes[0] & 0xFF) << 24 | (bytes[1] & 0xFF) << 16 | (bytes[2] & 0xFF) << 8 | bytes[3] & 0xFF; default: return 0; } } }