Java Integer Create toInt(byte[] bytes)

Here you can find the source of toInt(byte[] bytes)

Description

to Int

License

Open Source License

Declaration

public static int toInt(byte[] bytes) 

Method Source Code

//package com.java2s;
/*/*from   w  ww.  ja  va2  s.c o m*/
 * @(#)BytesHelper.java 2012-8-1 ????10:00:00
 *
 * Copyright (c) 2011-2012 Makersoft.org all rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *
 */

public class Main {
    public static int toInt(byte[] bytes) {
        int result = 0;
        for (int i = 0; i < 4; i++) {
            result = (result << 8) - Byte.MIN_VALUE + (int) bytes[i];
        }
        return result;
    }

    public static int toInt(byte[] bytes, int startIndex) {
        int result = 0;
        for (int i = startIndex; i < 4; i++) {
            result = (result << 8) | (bytes[i] & 0xFF);
        }
        return result;
    }
}

Related

  1. toInt(byte[] byteArray)
  2. toInt(byte[] bytes)
  3. toInt(byte[] bytes)
  4. toInt(byte[] bytes)
  5. toInt(byte[] bytes)
  6. toInt(byte[] bytes)
  7. toInt(byte[] bytes)
  8. toInt(byte[] bytes)
  9. toInt(byte[] bytes)