将一个byte数组转换成62进制的字符串。

@param bytes  二进制数组
@param noCase 区分大小写

@return 62进制的字符串
773487
public static String bytesToString(byte[] bytes, boolean noCase) {
        char[] digits = noCase ? DIGITS_NOCASE : DIGITS;
        int digitsLength = digits.length;

        if (ArrayUtils.isEmpty(bytes)) {
            return String.valueOf(digits[0]);
        }

        StringBuilder strValue = new StringBuilder();
        int value = 0;
        int limit = Integer.MAX_VALUE >>> 8;
        int i = 0;

        do {
            while (i < bytes.length && value < limit) {
                value = (value << 8) + (0xFF & bytes[i++]);
            }

            while (value >= digitsLength) {
                strValue.append(digits[value % digitsLength]);
                value = value / digitsLength;
            }
        } while (i < bytes.length);

        if (value != 0 || strValue.length() == 0) {
            strValue.append(digits[value]);
        }

        return strValue.toString();
    }
511151
public static long registersToLong(byte[] bytes) {
        return ((((long)(bytes[0] & 0xff) << 56) |
                ((long)(bytes[1] & 0xff) << 48) |
                ((long)(bytes[2] & 0xff) << 40) |
                ((long)(bytes[3] & 0xff) << 32) |
                ((long)(bytes[4] & 0xff) << 24) |
                ((long)(bytes[5] & 0xff) << 16) |
                ((long)(bytes[6] & 0xff) << 8) |
                ((long)(bytes[7] & 0xff)))
        );
    }
1100703
public final int strLengthNull(byte[]bytes, int p, int end) {
        int n = 0;

        while (true) {
            if (bytes[p] == 0) {
                int len = minLength();

                if (len == 1) return n;
                int q = p + 1;

                while (len > 1) {
                    if (bytes[q] != 0) break;
                    q++;
                    len--;
                }
                if (len == 1) return n;
            }
            p += length(bytes, p, end);
            n++;
        }
    }
526970
public int expectUnsigned(int bytes) throws IOException {
        switch (bytes) {
            case 4:
                return expectUInt32();
            case 3:
                return expectUInt24();
            case 2:
                return expectUInt16();
            case 1:
                return expectUInt8();
        }
        throw new IllegalArgumentException("Unsupported byte count for unsigned: " + bytes);
    }
373649
public static long bytesToLong(byte[] bytes) {
		// Magic number 8 should be defined as Long.SIZE / Byte.SIZE
		long values = 0;
		for (int i = 0; i < 8; i++) {
			values <<= 8;
			values |= (bytes[i] & 0xff);
		}
		return values;
	}
826844
public static String hex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for (int j = 0; j < bytes.length; j++) {
            int v = bytes[j] & 0xFF;
            hexChars[j * 2] = HEXES_SMALL[v >>> 4];
            hexChars[j * 2 + 1] = HEXES_SMALL[v & 0x0F];
        }
        return new String(hexChars);
    }
961823
private static byte _getByte(int startIndex, BitSetStrictLength set)
			throws AsnException {

		int count = 8;
		byte data = 0;

//		if (set.length() - 1 < startIndex) {
//			throw new AsnException();
//		}

		while (count > 0) {
			if (set.length() - 1 < startIndex) {
				break;
			} else {
				boolean lit = set.get(startIndex);
				if (lit) {
					data |= (0x01 << (count - 1));
				}

				startIndex++;
				count--;
			}

		}
		return data;
	}
1074541
public static String encode(byte[] bytes) {
		int bytesLength = bytes.length;
		int base64Length = (bytesLength * 4 + 2) / 3; // base64 encoded string length, without padding

		StringBuilder base64Builder = new StringBuilder();
		int bytesIndex = 0;

		while (bytesIndex < bytesLength) {
			int i0 = bytes[bytesIndex++] & 0xff;
			int i1 = bytesIndex < bytesLength ? bytes[bytesIndex++] & 0xff : 0;
			int i2 = bytesIndex < bytesLength ? bytes[bytesIndex++] & 0xff : 0;

			int o0 = i0 >>> 2;
			int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
			int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
			int o3 = i2 & 0x3F;

			base64Builder.append(NIBLES_2_CHARS[o0]);
			base64Builder.append(NIBLES_2_CHARS[o1]);
			base64Builder.append(base64Builder.length() < base64Length ? NIBLES_2_CHARS[o2] : '=');
			base64Builder.append(base64Builder.length() < base64Length ? NIBLES_2_CHARS[o3] : '=');
		}

		return base64Builder.toString();
	}
768438
public static String byte2FitMemorySize(final long byteNum) {
        if (byteNum < 0) {
            return "shouldn't be less than zero!";
        } else if (byteNum < MemoryConst.KB) {
            return String.format("%.3fB", (double) byteNum);
        } else if (byteNum < MemoryConst.MB) {
            return String.format("%.3fKB", (double) byteNum / MemoryConst.KB);
        } else if (byteNum < MemoryConst.GB) {
            return String.format("%.3fMB", (double) byteNum / MemoryConst.MB);
        } else {
            return String.format("%.3fGB", (double) byteNum / MemoryConst.GB);
        }
    }
38288
public static String byteToBits(byte b) {
        return ""
            + (byte) ((b >> 7) & 0x01) + (byte) ((b >> 6) & 0x1)
            + (byte) ((b >> 5) & 0x01) + (byte) ((b >> 4) & 0x1)
            + (byte) ((b >> 3) & 0x01) + (byte) ((b >> 2) & 0x1)
            + (byte) ((b >> 1) & 0x01) + (byte) ((b >> 0) & 0x1);
    }
694886
function getBytesWithUnit(bytes) {
        if (isNaN(bytes)) {
            return;
        }
        var units = [ ' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB' ];
        var amountOf2s = Math.floor(Math.log(+bytes) / Math.log(2));
        if (amountOf2s < 1) {
            amountOf2s = 0;
        }
        var i = Math.floor(amountOf2s / 10);
        bytes = +bytes / Math.pow(2, 10 * i);


        if (bytes.toString().length > bytes.toFixed(2).toString().length) {
            bytes = bytes.toFixed(2);
        }
        return bytes + units[i];
    }
422804
public static String encodeBytes(byte[] bytes)
    {
        String ret = null;

        try
        {
            // Obfuscate the string
            if(bytes != null)
                ret = new String(Base64.encodeBase64(bytes));
        }
        catch(NoClassDefFoundError e)
        {
            ret = new String(bytes);
            System.out.println("WARNING: unable to encode: "
                +e.getClass().getName()+": "+e.getMessage());
        }

        return ret;
    }
691392
public static String bytesToBase64Str(byte[] bytes) {
        if (ArrayUtils.isEmpty(bytes)) {
            return null;
        }
        Base64.Encoder encoder = Base64.getEncoder();
        String base64Str = encoder.encodeToString(bytes);
        return base64Str;
    }
1276693
function(number, bytes) {
        if (number < 0) {
            throw new Error('"number" must greater than or equal to zero.')
        }
        bytes = bytes || 8
        var bn = new BigNumber(String(number))
        // 转换为16进制字符串
        var hex = bn.toString(16)

        // ------- 将hex length补充成bytes x 2，不足则高位补0，超过则去掉高位
        var length = hex.length
        var targetLength = bytes * 2
        if (length < targetLength) {
            var i = targetLength - length
            while (i > 0) {
                hex = '0' + hex
                i--
            }

        } else if (length > targetLength) {
            hex = hex.substring(length - targetLength)
        }

        // ------ 填充到buffer里，高位在前
        var buffer = new Buffer(bytes)
        var offset = 0
        while (offset < bytes) {
            var bn = Number("0x" + hex.substring(offset * 2, (offset * 2) + 2))
            buffer.writeUInt8(bn, offset)
            offset++
        }

        return buffer
    }
1225134
static public byte[] asBytes(int value) {

        if (0 > value) {
            throw new IllegalArgumentException("value cannot be less than zero");
        }

        byte[] result = new byte[4];
        result[0] = (byte) ((value >>> 24) & 0xFF);
        result[1] = (byte) ((value >>> 16) & 0xFF);
        result[2] = (byte) ((value >>> 8) & 0xFF);
        result[3] = (byte) ((value) & 0xFF);
        return result;
    }
248440
private int s2i(final byte[] bytes) {
    int num = 0;
    for (int i = 0; i < 4; i++) {
      num += (bytes[i] & 0xff) << ((3 - i) * 8);
    }
    return num;
  }
771502
public static String toHex(byte[] bytes) {
    StringBuffer buffer = new StringBuffer();

    for (byte b : bytes) {
      buffer.append(String.format("%02X", b));
    }

    return buffer.toString();
  }