diff --git a/plugins/ets/stdlib/std/core/Byte.ets b/plugins/ets/stdlib/std/core/Byte.ets index d8650ce89d9c11a69fb533fc79385f1a5e563b1f..508e4f7c51e1270b74ecbe0432a21d93fea780e2 100644 --- a/plugins/ets/stdlib/std/core/Byte.ets +++ b/plugins/ets/stdlib/std/core/Byte.ets @@ -189,6 +189,15 @@ export final class Byte extends Integral implements Comparable, JSONable, JSONable, JSONable 36) { + throw new RangeError('Radix must be between 2 and 36'); + } + if (this.value == 0) { + return "0"; + } + const chars = '0123456789abcdefghijklmnopqrstuvwxyz'; + let val = this.value; + let negative: boolean = (val < 0); + let digitsNum = (log(abs(val)) / log(radix as int) + 1) as int; + if (negative) { + ++digitsNum; + } + let data = new char[digitsNum]; + let curPlace = digitsNum - 1; + while (val != 0) { + let remainder = val % (radix as int); + if (negative) { + remainder = -remainder; + } + data[curPlace] = chars.charAt(remainder as int); + val /= (radix as int); + curPlace -= 1; + } + if (negative) { + data[0] = c'-'; + } + return new String(data); + } + /** * Returns a hash code (integer representation) for this instance * diff --git a/plugins/ets/stdlib/std/core/Short.ets b/plugins/ets/stdlib/std/core/Short.ets index 45f097a91509ac0dc4781245fb1ad4f6be41e44a..f87d8bc58cc816f9d221b86d72adcbb1fbc52d05 100644 --- a/plugins/ets/stdlib/std/core/Short.ets +++ b/plugins/ets/stdlib/std/core/Short.ets @@ -188,6 +188,15 @@ export final class Short extends Integral implements Comparable, JSONable return new String(data); } + /** + * Converts this object to a string + * + * @returns result of the conversion + */ + public toString(radix: number): string { + return (new Long(this.value)).toString(radix); + } + /** * Returns a hash code (shorteger representation) for this instance *