Converts a constant in internal representation (in which
boolean, char, byte, short, and int are each represented by an
Integer) into standard representation.  Other values (including
null) are returned unchanged.
4744
public static Object decode(Object value, Type type) {
        if (value instanceof Integer) {
            int i = (Integer) value;
            switch (type.getTag()) {
            case BOOLEAN:  return i != 0;
            case CHAR:     return (char) i;
            case BYTE:     return (byte) i;
            case SHORT:    return (short) i;
            }
        }
        return value;
    }
1239757
public static byte[] getVariableByteUnsigned(int value) {
        if (value < 0) {
            throw new InvalidParameterException("negative value not allowed: " + value);
        } else if (value < 128) { // 2^7
            // encode the number in a single byte
            return new byte[]{(byte) value};
        } else if (value < 16384) { // 2^14
            // encode the number in two bytes
            return new byte[]{(byte) (value | 0x80), (byte) (value >> 7)};
        } else if (value < 2097152) { // 2^21
            // encode the number in three bytes
            return new byte[]{(byte) (value | 0x80), (byte) ((value >> 7) | 0x80), (byte) (value >> 14)};
        } else if (value < 268435456) { // 2^28
            // encode the number in four bytes
            return new byte[]{(byte) (value | 0x80), (byte) ((value >> 7) | 0x80), (byte) ((value >> 14) | 0x80),
                    (byte) (value >> 21)};
        } else {
            // encode the number in five bytes
            return new byte[]{(byte) (value | 0x80), (byte) ((value >> 7) | 0x80), (byte) ((value >> 14) | 0x80),
                    (byte) ((value >> 21) | 0x80), (byte) (value >> 28)};
        }
    }
1204736
def p_const_value_primitive(self, p):
        ''''''
        p[0] = ast.ConstPrimitiveValue(p[1], lineno=p.lineno(1))
1352937
private int readInteger() {
        int b = buf.get();
        if (buf.hasRemaining()) {
            int n = 0;
            int result = 0;
            while ((b & 0x80) != 0 && n < 3) {
                result <<= 7;
                result |= (b & 0x7f);
                b = buf.get();
                n++;
            }
            if (n < 3) {
                result <<= 7;
                result |= b;
            } else {
                // use all 8 bits from the 4th byte
                result <<= 8;
                result |= b & 0x0ff;
                // check if the integer should be negative
                if ((result & 0x10000000) != 0) {
                    // extend the sign bit
                    result |= 0xe0000000;
                }
            }
            return result;
        }
        return b;
    }
1261993
public static int toInt(byte[] b, int off, boolean littleEndian) {
		if (littleEndian) {
			return (b[off] & 0xFF) | ((b[off + 1] & 0xFF) << 8) |
					((b[off + 2] & 0xFF) << 16) | ((b[off + 3] & 0xFF) << 24);
		}
		return ((b[off] & 0xFF) << 24) | ((b[off + 1] & 0xFF) << 16) |
				((b[off + 2] & 0xFF) << 8) | (b[off + 3] & 0xFF);
	}
1020808
function encodeNumber(buf, value, len) {
  var index = 0;
  
  while (len > 0) {
    var tmpValue = value >>> ((len - 1) * 8);
    buf[index++] = tmpValue & 0xFF;
    len--;
  }
}
517589
def _int_size(x):
    """"""
    if -0x80 <= x <= 0x7F:
        return 1
    elif -0x8000 <= x <= 0x7FFF:
        return 2
    elif -0x80000000 <= x <= 0x7FFFFFFF:
        return 4
    elif long(-0x8000000000000000) <= x <= long(0x7FFFFFFFFFFFFFFF):
        return 8
    else:
        raise RuntimeError("Cannot represent value: " + str(x))
689942
public void encodeNBitUnsignedInteger(int b, int n) throws IOException {
		if (b < 0 || n < 0) {
			throw new IllegalArgumentException(
					"Negative value as unsigned integer!");
		}
		assert (b >= 0);
		assert (n >= 0);

		if (n == 0) {
			// 0 bytes
		} else if (n < 9) {
			// 1 byte
			encode(b & 0xff);
		} else if (n < 17) {
			// 2 bytes
			encode(b & 0x00ff);
			encode((b & 0xff00) >> 8);
		} else if (n < 25) {
			// 3 bytes
			encode(b & 0x0000ff);
			encode((b & 0x00ff00) >> 8);
			encode((b & 0xff0000) >> 16);
		} else if (n < 33) {
			// 4 bytes
			encode(b & 0x000000ff);
			encode((b & 0x0000ff00) >> 8);
			encode((b & 0x00ff0000) >> 16);
			encode((b & 0xff000000) >> 24);
		} else {
			throw new RuntimeException(
					"Currently not more than 4 Bytes allowed for NBitUnsignedInteger!");
		}
	}
1109665
public static int toChars(int i, char[] buf, int offset) {
        if (i < 0) {
            if (i == Integer.MIN_VALUE) {
                writeMinInteger(buf, offset);
                return offset + 11;
            }
            buf[offset++] = '-';
            i = -i;
        }

        offset += stringSizeOf(i);
        getChars(i, offset, buf);
        return offset;
    }
1159024
public static int encodeInteger(int value, ByteBuffer buf) {
        int pos = buf.position();
        int contentLength = 0;
        do {
            pos--;
            buf.put(pos, (byte) (value & 0xff));
            value >>>= 8;
            contentLength++;
        } while (value != 0);
        buf.position(buf.position() - contentLength);
        int headerLen = DerUtils.encodeIdAndLength(DerId.TagClass.UNIVERSAL, DerId.EncodingType.PRIMITIVE, ASN1_INTEGER_TAG_NUM,
                contentLength, buf);
        return headerLen + contentLength;
    }
1340319
private static void encodeInteger(ByteBuf out, int mask, int n, int i) {
        encodeInteger(out, mask, n, (long) i);
    }
939507
def _VarintBytes(value):
  """"""

  pieces = []
  _EncodeVarint(pieces.append, value)
  return b"".join(pieces)
32483
public static byte[] encodeInt(int i) {
		byte[] raw = new byte[4];
		raw[0] = (byte) (i >> 24);
		raw[1] = (byte) (i >> 16);
		raw[2] = (byte) (i >> 8);
		raw[3] = (byte) (i);
		return raw;
	}
955575
protected void normalizeAndPrint(char c, boolean isAttValue) {
        
        switch (c) {
            case '<': {
                fOut.print("&lt;");
                break;
            }
            case '>': {
                fOut.print("&gt;");
                break;
            }
            case '&': {
                fOut.print("&amp;");
                break;
            }
            case '"': {
                // A '"' that appears in character data
                // does not need to be escaped.
                if (isAttValue) {
                    fOut.print("&quot;");
                } else {
                    fOut.print("\"");
                }
                break;
            }
            case '\r': {
                // If CR is part of the document's content, it
                // must not be printed as a literal otherwise
                // it would be normalized to LF when the document
                // is reparsed.
                fOut.print("&#xD;");
                break;
            }
            case '\n': {
                if (fCanonical) {
                    fOut.print("&#xA;");
                    break;
                }
                // else, default print char
            }
            default: {
                // In XML 1.1, control chars in the ranges [#x1-#x1F, #x7F-#x9F] must be escaped.
                //
                // Escape space characters that would be normalized to #x20 in attribute values
                // when the document is reparsed.
                //
                // Escape NEL (0x85) and LSEP (0x2028) that appear in content
                // if the document is XML 1.1, since they would be normalized to LF
                // when the document is reparsed.
                if (fXML11 && ((c >= 0x01 && c <= 0x1F && c != 0x09 && c != 0x0A)
                || (c >= 0x7F && c <= 0x9F) || c == 0x2028)
                || isAttValue && (c == 0x09 || c == 0x0A)) {
                    fOut.print("&#x");
                    fOut.print(Integer.toHexString(c).toUpperCase());
                    fOut.print(";");
                } else {
                    fOut.print(c);
                }
            }
        }
    }
802596
public static Type toValueType(Type type) {
	if (type == Types.BYTE) return Types.BYTE_VALUE;
	if (type == Types.BOOLEAN) return Types.BOOLEAN_VALUE;
	if (type == Types.CHARACTER) return Types.CHAR;
	if (type == Types.DOUBLE) return Types.DOUBLE_VALUE;
	if (type == Types.FLOAT) return Types.FLOAT_VALUE;
	if (type == Types.INTEGER) return Types.INT_VALUE;
	if (type == Types.LONG) return Types.LONG_VALUE;
	if (type == Types.SHORT) return Types.SHORT_VALUE;

	return type;
    }
1251459
public static int inc(int value, int r, int g, int b)
    {
        final int alpha = value >> Constant.BYTE_4 & 0xFF;
        if (alpha == 0)
        {
            return 0;
        }
        final int red = value >> Constant.BYTE_3 & 0xFF;
        final int green = value >> Constant.BYTE_2 & 0xFF;
        final int blue = value >> Constant.BYTE_1 & 0xFF;

        final int alphaMask = (UtilMath.clamp(alpha, 0, 255) & 0xFF) << Constant.BYTE_4;
        final int redMask = (UtilMath.clamp(red + r, 0, 255) & 0xFF) << Constant.BYTE_3;
        final int greenMask = (UtilMath.clamp(green + g, 0, 255) & 0xFF) << Constant.BYTE_2;
        final int blueMask = (UtilMath.clamp(blue + b, 0, 255) & 0xFF) << Constant.BYTE_1;

        return alphaMask | redMask | greenMask | blueMask;
    }
203653
public static String encode(byte[] in) {
        if (in == null) {
            return null;
        }
        return encode(in, 0, in.length);
    }