java.lang.Character.forDigit()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(290)

本文整理了Java中java.lang.Character.forDigit()方法的一些代码示例,展示了Character.forDigit()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Character.forDigit()方法的具体详情如下:
包路径:java.lang.Character
类名称:Character
方法名:forDigit

Character.forDigit介绍

[英]Returns the character which represents the specified digit in the specified radix. The radix must be between MIN_RADIX and MAX_RADIX inclusive; digit must not be negative and smaller than radix. If any of these conditions does not hold, 0 is returned.
[中]返回表示指定基数中指定数字的字符。基数必须介于最小基数和最大基数之间(包括最小基数和最大基数);数字不得为负数且小于基数。如果这些条件中的任何一个不成立,则返回0。

代码示例

代码示例来源:origin: libgdx/libgdx

public static String bytesToHex (byte[] data, int len) {
  char[] hex = new char[len * 2];
  for (int i = 0; i < len; i++) {
    int di = data[i];
    hex[i << 1] = Character.forDigit((di >> 4) & 15, 16);
    hex[(i << 1) + 1] = Character.forDigit(di & 15, 16);
  }
  return new String(hex);
}

代码示例来源:origin: libgdx/libgdx

public static String bytesToHex (byte[] data, int len) {
  char[] hex = new char[len * 2];
  for (int i = 0; i < len; i++) {
    int di = data[i];
    hex[i << 1] = Character.forDigit((di >> 4) & 15, 16);
    hex[(i << 1) + 1] = Character.forDigit(di & 15, 16);
  }
  return new String(hex);
}

代码示例来源:origin: stackoverflow.com

if (i >= 0 && i <= 9) {
char c = Character.forDigit(i, 10);
....
}

代码示例来源:origin: Tencent/tinker

/**
 * Formats an {@code int} as a 4-bit unsigned hex nibble.
 *
 * @param v value to format
 * @return {@code non-null;} formatted form
 */
public static String uNibble(int v) {
  char[] result = new char[1];
  result[0] = Character.forDigit(v & 0x0f, 16);
  return new String(result);
}

代码示例来源:origin: Tencent/tinker

/**
 * Formats a {@code long} as an 8-byte unsigned hex value.
 *
 * @param v value to format
 * @return {@code non-null;} formatted form
 */
public static String u8(long v) {
  char[] result = new char[16];
  for (int i = 0; i < 16; i++) {
    result[15 - i] = Character.forDigit((int) v & 0x0f, 16);
    v >>= 4;
  }
  return new String(result);
}

代码示例来源:origin: Tencent/tinker

/**
 * Formats an {@code int} as a 4-byte unsigned hex value.
 *
 * @param v value to format
 * @return {@code non-null;} formatted form
 */
public static String u4(int v) {
  char[] result = new char[8];
  for (int i = 0; i < 8; i++) {
    result[7 - i] = Character.forDigit(v & 0x0f, 16);
    v >>= 4;
  }
  return new String(result);
}

代码示例来源:origin: Tencent/tinker

/**
 * Formats an {@code int} as a 3-byte unsigned hex value.
 *
 * @param v value to format
 * @return {@code non-null;} formatted form
 */
public static String u3(int v) {
  char[] result = new char[6];
  for (int i = 0; i < 6; i++) {
    result[5 - i] = Character.forDigit(v & 0x0f, 16);
    v >>= 4;
  }
  return new String(result);
}

代码示例来源:origin: Tencent/tinker

/**
 * Formats an {@code int} as a 2-byte unsigned hex value.
 *
 * @param v value to format
 * @return {@code non-null;} formatted form
 */
public static String u2(int v) {
  char[] result = new char[4];
  for (int i = 0; i < 4; i++) {
    result[3 - i] = Character.forDigit(v & 0x0f, 16);
    v >>= 4;
  }
  return new String(result);
}

代码示例来源:origin: Tencent/tinker

/**
 * Formats an {@code int} as a 1-byte unsigned hex value.
 *
 * @param v value to format
 * @return {@code non-null;} formatted form
 */
public static String u1(int v) {
  char[] result = new char[2];
  for (int i = 0; i < 2; i++) {
    result[1 - i] = Character.forDigit(v & 0x0f, 16);
    v >>= 4;
  }
  return new String(result);
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Returns the upper case hex digit of the lower 4 bits of the int.
 *
 * @param b the input int
 * @return the upper case hex digit of the lower 4 bits of the int.
 */
static char hexDigit(final int b) {
  return Character.toUpperCase(Character.forDigit(b & 0xF, RADIX));
}

代码示例来源:origin: Tencent/tinker

/**
 * Formats an {@code int} as a 2-byte signed hex value.
 *
 * @param v value to format
 * @return {@code non-null;} formatted form
 */
public static String s2(int v) {
  char[] result = new char[5];
  if (v < 0) {
    result[0] = '-';
    v = -v;
  } else {
    result[0] = '+';
  }
  for (int i = 0; i < 4; i++) {
    result[4 - i] = Character.forDigit(v & 0x0f, 16);
    v >>= 4;
  }
  return new String(result);
}

代码示例来源:origin: Tencent/tinker

/**
 * Formats an {@code int} as a 4-byte signed hex value.
 *
 * @param v value to format
 * @return {@code non-null;} formatted form
 */
public static String s4(int v) {
  char[] result = new char[9];
  if (v < 0) {
    result[0] = '-';
    v = -v;
  } else {
    result[0] = '+';
  }
  for (int i = 0; i < 8; i++) {
    result[8 - i] = Character.forDigit(v & 0x0f, 16);
    v >>= 4;
  }
  return new String(result);
}

代码示例来源:origin: Tencent/tinker

/**
 * Formats an {@code int} as a 1-byte signed hex value.
 *
 * @param v value to format
 * @return {@code non-null;} formatted form
 */
public static String s1(int v) {
  char[] result = new char[3];
  if (v < 0) {
    result[0] = '-';
    v = -v;
  } else {
    result[0] = '+';
  }
  for (int i = 0; i < 2; i++) {
    result[2 - i] = Character.forDigit(v & 0x0f, 16);
    v >>= 4;
  }
  return new String(result);
}

代码示例来源:origin: Tencent/tinker

/**
 * Formats a {@code long} as an 8-byte signed hex value.
 *
 * @param v value to format
 * @return {@code non-null;} formatted form
 */
public static String s8(long v) {
  char[] result = new char[17];
  if (v < 0) {
    result[0] = '-';
    v = -v;
  } else {
    result[0] = '+';
  }
  for (int i = 0; i < 16; i++) {
    result[16 - i] = Character.forDigit((int) v & 0x0f, 16);
    v >>= 4;
  }
  return new String(result);
}

代码示例来源:origin: stanfordnlp/CoreNLP

/**
 * This returns a string from decimal digit smallestDigit to decimal digit
 * biggest digit. Smallest digit is labeled 1, and the limits are
 * inclusive.
 */
public static String truncate(int n, int smallestDigit, int biggestDigit) {
 int numDigits = biggestDigit - smallestDigit + 1;
 char[] result = new char[numDigits];
 for (int j = 1; j < smallestDigit; j++) {
  n = n / 10;
 }
 for (int j = numDigits - 1; j >= 0; j--) {
  result[j] = Character.forDigit(n % 10, 10);
  n = n / 10;
 }
 return new String(result);
}

代码示例来源:origin: mpusher/mpush

private static String toHex(byte[] bytes) {
  StringBuilder buffer = new StringBuilder(bytes.length * 2);
  for (int i = 0; i < bytes.length; ++i) {
    buffer.append(Character.forDigit((bytes[i] & 240) >> 4, 16));
    buffer.append(Character.forDigit(bytes[i] & 15, 16));
  }
  return buffer.toString();
}

代码示例来源:origin: stackoverflow.com

/**
 * Converts the number to a String in a given radix.
 * This uses {@link Character.digit} to convert each digit
 * to one character.
 * @param radix the radix to use, between {@link Character.MIN_RADIX}
 *   and {@link Character.MAX_RADIX}.
 * @return a String containing the digits of this number in the
 *   specified radix, using '0' .. '9' and 'a' .. 'z' (as much as needed).
 */
public String toString(int radix) {
  if(radix < Character.MIN_RADIX || Character.MAX_RADIX < radix) {
    throw new IllegalArgumentException("radix out of range: " + radix);
  }
  if(digits.length == 0)
    return "0";
  int[] rdigits = convertTo(radix);
  StringBuilder b = new StringBuilder(rdigits.length);
  for(int dig : rdigits) {
    b.append(Character.forDigit(dig, radix));
  }
  return b.toString();
}

代码示例来源:origin: spring-projects/spring-framework

char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16));
char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16));
bos.write(hex1);
bos.write(hex2);

代码示例来源:origin: spring-projects/spring-framework

char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16));
char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16));
sb.append(hex1);
sb.append(hex2);

代码示例来源:origin: apache/ignite

/**
 * @param len Length.
 * @return Test string.
 */
private static String generateTestString(int len) {
  assert len > 0;
  SB sb = new SB();
  for (int i = 0; i < len; i++)
    sb.a(Character.forDigit(i % 10, 10));
  return sb.toString();
}

相关文章

Character类方法