[Method] 8진수로 변환하는데 메서드 하나만 써도되는 이유

Subject : 8진수로 변환하는데 메서드 하나만 써도되는 이유

Object
  • To think how to change Decimal value to Octals.

/** Output:
 Octal is 24
 Hexadecimal is 14
 */

public class MainClass {
  public static void main(String args[]) {
    int i = 20;
    System.out.println("Octal is " + Integer.toOctalString(i));
  }
}

As soon as I used a method "toOctalString", I wondered how to process in the method
It calls "toUnsignedString(int i, int shift)" in the method.

Integer.class
String toUnsignedString(int i, int shift) {
char[] buf = new char[32];
int charPos = 32;
int radix = 1 << shift; // when it comes 3, radix is 8, 4 -> 16
int mask = radix - 1;
do {
buf[--charPos] = digits[i & mask]; // It's used by a Bitewise operator.
i >>>= shift;
} while (i != 0);
return new String(buf, charPos, (32 - charPos));
}


Related links

댓글

가장 많이 본 글