A int was written by flipping the sign bit, and writing it as a big endian
int.

To decode, we do the reverse, flipping the sign bit, and reading the int
from the bytes.

@return The decoded int.
437755
@Override
  public int readInt() throws IOException {
    byte[] intBytes = new byte[4];
    int i = in.read(intBytes);
    if (i < 4) {
      throw new EOFException();
    }
    intBytes[0] = (byte) (intBytes[0] ^ 0x80);

    int value = 0;
    for (int j = 0; j < intBytes.length; ++j) {
      value = (value << 8) + (intBytes[j] & 0xff);
    }
    return value;
  }
47537
public int read_int() throws OtpErlangDecodeException {
        final long l = this.read_long(false);
        final int i = (int) l;

        if (l != i) {
            throw new OtpErlangDecodeException("Value does not fit in int: "
                    + l);
        }

        return i;
    }
1339958
def decint(n, signed=False):  # pylint: disable=invalid-name,too-many-branches
    

    if isinstance(n, str):
        n = utils.to_string(n)

    if n is True:
        return 1

    if n is False:
        return 0

    if n is None:
        return 0

    if is_numeric(n):
        if signed:
            if not -TT255 <= n <= TT255 - 1:
                raise EncodingError('Number out of range: %r' % n)
        else:
            if not 0 <= n <= TT256 - 1:
                raise EncodingError('Number out of range: %r' % n)

        return n

    if is_string(n):
        if len(n) > 32:
            raise EncodingError('String too long: %r' % n)

        if len(n) == 40:
            int_bigendian = decode_hex(n)
        else:
            int_bigendian = n  # pylint: disable=redefined-variable-type

        result = big_endian_to_int(int_bigendian)
        if signed:
            if result >= TT255:
                result -= TT256

            if not -TT255 <= result <= TT255 - 1:
                raise EncodingError('Number out of range: %r' % n)
        else:
            if not 0 <= result <= TT256 - 1:
                raise EncodingError('Number out of range: %r' % n)

        return result

    raise EncodingError('Cannot decode integer: %r' % n)
428543
public static final byte highBit(int n)
    {
        if (n <= 0) {
            return -1;
        }

        byte bit = 0;

        if (n >= 1 << 16) {
            n >>= 16;
        bit += 16;
        }

        if (n >= 1 << 8) {
            n >>= 8;
        bit += 8;
        }

        if (n >= 1 << 4) {
            n >>= 4;
        bit += 4;
        }

        if (n >= 1 << 2) {
            n >>= 2;
        bit += 2;
        }

        if (n >= 1 << 1) {
            n >>= 1;
        bit += 1;
        }

        return bit;
    }
1038581
public static int decode(CharIterator in) {
    int result = 0;
    boolean continuation;
    int shift = 0;
    do {
      char c = in.next();
      int digit = Base64.fromBase64(c);
      continuation = (digit & VLQ_CONTINUATION_BIT) != 0;
      digit &= VLQ_BASE_MASK;
      result = result + (digit << shift);
      shift = shift + VLQ_BASE_SHIFT;
    } while (continuation);

    return fromVLQSigned(result);
  }
1050762
public int decodeDigits(ByteArrayInputStream bis) throws ParameterException {
        if(skipDigits()){
            return 0;
        }
        if (bis.available() == 0) {
            throw new ParameterException("No more data to read.");
        }

        // FIXME: we could spare time by passing length arg - or getting it from
        // bis??
        int count = 0;
        try {
            address = "";
            int b = 0;
            while (bis.available() - 1 > 0) {
                b = (byte) bis.read();

                int d1 = b & 0x0f;
                int d2 = (b & 0xf0) >> 4;

                address += Integer.toHexString(d1) + Integer.toHexString(d2);

            }

            b = bis.read() & 0xff;
            address += Integer.toHexString((b & 0x0f));

            if (oddFlag != _FLAG_ODD) {
                address += Integer.toHexString((b & 0xf0) >> 4);
            }
            this.setAddress(address);
        } catch (Exception e) {
            throw new ParameterException(e);
        }
        return count;
    }
1359712
public BEValue bdecodeNumber() throws IOException {
    int c = this.getNextIndicator();
    if (c != 'i') {
      throw new InvalidBEncodingException("Expected 'i', not '" +
              (char) c + "'");
    }
    this.indicator = 0;

    c = this.read();
    if (c == '0') {
      c = this.read();
      if (c == 'e')
        return new BEValue(BigInteger.ZERO);
      else
        throw new InvalidBEncodingException("'e' expected after zero," +
                " not '" + (char) c + "'");
    }

    // We don't support more the 255 char big integers
    char[] chars = new char[256];
    int off = 0;

    if (c == '-') {
      c = this.read();
      if (c == '0')
        throw new InvalidBEncodingException("Negative zero not allowed");
      chars[off] = '-';
      off++;
    }

    if (c < '1' || c > '9')
      throw new InvalidBEncodingException("Invalid Integer start '"
              + (char) c + "'");
    chars[off] = (char) c;
    off++;

    c = this.read();
    int i = c - '0';
    while (i >= 0 && i <= 9) {
      chars[off] = (char) c;
      off++;
      c = read();
      i = c - '0';
    }

    if (c != 'e')
      throw new InvalidBEncodingException("Integer should end with 'e'");

    String s = new String(chars, 0, off);
    return new BEValue(new BigInteger(s));
  }
1097845
protected int getInt()
  {
    if (tc.isEntryEnabled()) Tr.entry(tc, "getInt",this);

    int data = _buffer.getInt();

    if (tc.isEntryEnabled()) Tr.exit(tc, "getInt",new Integer(data));
    return data;
  }
424064
public BigInteger readMPINT() throws IOException {
		short bits = readShort();

		byte[] raw = new byte[(bits + 7) / 8 + 1];

		raw[0] = 0;
		readFully(raw, 1, raw.length - 1);

		return new BigInteger(raw);
	}
1159426
private static int decode(final int hex) {
        if (hex >= CcHex.BACK.length) {
            throw new DecodingException(
                String.format("invalid hex char: 0x%2x", hex)
            );
        }
        final int dec = CcHex.BACK[hex];
        if (dec < 0) {
            throw new DecodingException(
                String.format("invalid hex character: 0x%2x", hex)
            );
        }
        return dec;
    }
685272
@Override
	public int readBit() {
		if (position == size) throw new EndOfBitStreamException();
		int count = (int) position & 7;
		if (count == 0) { // need new bits
			buffer = readByte();
			if (buffer == -1) throw new EndOfBitStreamException();
		}
		position++;
		// other endian
		// return (buffer >> count) & 1;
		return (buffer >> (7 - count)) & 1;
	}
590099
public static Number decode_long(byte[] data) {
		if (data.length == 0)
			return 0L;
		// first reverse the byte array because pickle stores it little-endian
		byte[] data2 = new byte[data.length];
		for (int i = 0; i < data.length; ++i)
			data2[data.length - i - 1] = data[i];
		BigInteger bigint = new BigInteger(data2);
		return optimizeBigint(bigint);
	}
1151157
public int read() throws IOException {
    // Read the next non-whitespace character
    int x;
    do {
      x = in.read();
      if (x == -1) {
        return -1;
      }
    } while (Character.isWhitespace((char) x));
    charCount++;

    // The '=' sign is just padding
    if (x == '=') {
      return -1; // effective end of stream
    }

    // Convert from raw form to 6-bit form
    x = ints[x];

    // Calculate which character we're decoding now
    int mode = (charCount - 1) % 4;

    // First char save all six bits, go for another
    if (mode == 0) {
      carryOver = x & 63;
      return read();
    }
    // Second char use previous six bits and first two new bits,
    // save last four bits
    else if (mode == 1) {
      int decoded = ((carryOver << 2) + (x >> 4)) & 255;
      carryOver = x & 15;
      return decoded;
    }
    // Third char use previous four bits and first four new bits,
    // save last two bits
    else if (mode == 2) {
      int decoded = ((carryOver << 4) + (x >> 2)) & 255;
      carryOver = x & 3;
      return decoded;
    }
    // Fourth char use previous two bits and all six new bits
    else if (mode == 3) {
      int decoded = ((carryOver << 6) + x) & 255;
      return decoded;
    }
    return -1; // can't actually reach this line
  }
549872
def decode_int(v):
    """"""
    if len(v) > 0 and (v[0] == b'\x00' or v[0] == 0):
        raise Exception("No leading zero bytes allowed for integers")
    return big_endian_to_int(v)
1111310
protected static int readInt(InputStream input, int bytesNumber, boolean bigEndian) throws IOException
    {
        final int oneByte = 8;
        int ret = 0;
        int sv;
        if (bigEndian)
        {
            sv = (bytesNumber - 1) * oneByte;
        }
        else
        {
            sv = 0;
        }
        final int cnt;
        if (bigEndian)
        {
            cnt = -oneByte;
        }
        else
        {
            cnt = oneByte;
        }
        for (int i = 0; i < bytesNumber; i++)
        {
            ret |= input.read() << sv;
            sv += cnt;
        }
        return ret;
    }
250273
private static String decode(String s) {
    int n = INITIAL_N;
    int i = 0;
    int bias = INITIAL_BIAS;
    StringBuffer output = new StringBuffer();
    int d = s.lastIndexOf(DELIMITER);
    if (d > 0) {
      for (int j = 0; j < d; j++) {
        char c = s.charAt(j);
        if (!basicCodePoint(c)) {
          throw new IllegalArgumentException("bad input: " + c);
        }
        output.append(c);
      }
      d++;
    } else {
      d = 0;
    }
    while (d < s.length()) {
      int oldi = i;
      int w = 1;
      for (int k = BASE;; k += BASE) {
        if (d == s.length()) {
          throw new IllegalArgumentException("bad input: " + d);
        }
        int c = s.charAt(d++);
        int digit = decodeDigit(c);
        if (digit > (Integer.MAX_VALUE - i) / w) {
          throw new IllegalArgumentException("encoding overflow");
        }
        i = i + digit * w;
        int t;
        if (k <= bias) {
          t = TMIN;
        } else if (k >= bias + TMAX) {
          t = TMAX;
        } else {
          t = k - bias;
        }
        if (digit < t) {
          break;
        }
        w = w * (BASE - t);
      }
      bias = adapt(i - oldi, output.length() + 1, oldi == 0);
      if (i / (output.length() + 1) > Integer.MAX_VALUE - n) {
        throw new IllegalArgumentException("encoding overflow");
      }
      n = n + i / (output.length() + 1);
      i = i % (output.length() + 1);
      output.insert(i, (char) n);
      i++;
    }

    return output.toString();
  }
1032220
public int readInt(int off) {
		this.buffer.rewind();
		return ((buffer.get(off++) & 0xFF) << 24)
				| ((buffer.get(off++) & 0xFF) << 16)
				| ((buffer.get(off++) & 0xFF) << 8)
				| (buffer.get(off++) & 0xFF);
	}