/** * Get a string version of the given value. * * @param val the value * @return the string */ public static ByteString fromInt(int val) { if (val == 0) return ZERO; // afaik no faster way exists to do this int i = decimalCount(abs(val)); final byte[] b; if (val < 0) { b = new byte[++i]; b[0] = '-'; } else { b = new byte[i]; } int quo; // modulus int mod; do { quo = val / 10; mod = val - ((quo << 3) + (quo << 1)); b[--i] = (byte) (mod + '0'); val = quo; } while (i > 0); return new ByteString(b); }
/** * Get a string version of the given value. * * @param val the value * @return the string */ public static ByteString fromLong(long val) { if (val == 0) return ZERO; // afaik no faster way exists to do this int i = decimalCount(abs(val)); final byte[] b; if (val < 0) { b = new byte[++i]; b[0] = '-'; } else { b = new byte[i]; } long quo; // modulus int mod; do { quo = val / 10; mod = (int) (val - ((quo << 3) + (quo << 1))); b[--i] = (byte) (mod + '0'); val = quo; } while (i > 0); return new ByteString(b); }
/** * Get a string version of the given value. * * @param val the value * @return the string */ public static ByteString fromInt(int val) { if (val == 0) return ZERO; // afaik no faster way exists to do this int i = decimalCount(abs(val)); final byte[] b; if (val < 0) { b = new byte[++i]; b[0] = '-'; } else { b = new byte[i]; } int quo; // modulus int mod; do { quo = val / 10; mod = val - ((quo << 3) + (quo << 1)); b[--i] = (byte) (mod + '0'); val = quo; } while (i > 0); return new ByteString(b); }
/** * Get a string version of the given value. * * @param val the value * @return the string */ public static ByteString fromLong(long val) { if (val == 0) return ZERO; // afaik no faster way exists to do this int i = decimalCount(abs(val)); final byte[] b; if (val < 0) { b = new byte[++i]; b[0] = '-'; } else { b = new byte[i]; } long quo; // modulus int mod; do { quo = val / 10; mod = (int) (val - ((quo << 3) + (quo << 1))); b[--i] = (byte) (mod + '0'); val = quo; } while (i > 0); return new ByteString(b); }