Android Byte Array to Int Convert getInt(byte[] buffer, int pos, int count)

Here you can find the source of getInt(byte[] buffer, int pos, int count)

Description

Get integer?

License

Open Source License

Parameter

Parameter Description
buffer a parameter
pos a parameter
count a parameter

Declaration

public static int getInt(byte[] buffer, int pos, int count) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w w w  .  java  2  s  .  c  o  m*/
     * Get integer?
     * @param buffer
     * @param pos
     * @param count
     * @return
     */
    public static int getInt(byte[] buffer, int pos, int count) {
        int ret = 0;
        for (int i = 0; i < 4 && i < count && (i + pos) < buffer.length; i++) {
            ret *= 256;
            ret += toUnsignedInteger(buffer[i + pos]);
        }
        return ret;
    }

    /**
     * Convert byte to unsigned integer.
     * @param b
     * @return
     */
    public static int toUnsignedInteger(byte b) {
        int n = b >= 0 ? b : b + 256;
        return n;
    }
}

Related

  1. getInt(byte[] bb, int index)
  2. getInt(byte[] bb, int index)
  3. getInt(byte[] bb, int index)
  4. getInt(byte[] buf, boolean bigEndian)
  5. getInt(byte[] buf, int pos, boolean bigEndian)
  6. getInt(byte[] bytes)
  7. getInt(int offset, byte[] fromBytes)
  8. getInt2(byte[] b, int offset)
  9. getInt3(byte[] b, int offset)