types.Integer.tochar
Method on every
integerConverts the integer to a one-character string, treating it as a character code.
Return value
A string of length 1 whose only byte is this cast to char.
Notes
Takes no arguments. The cast wraps modulo 256 and keeps no sign information, the same as a C (char) cast: (65).tochar() and (65 + 256).tochar() give the same character. A negative or out-of-[0, 255] value does not throw, it wraps.
This method also exists on float and bool (see types.Float.tochar and types.Bool.tochar); bool's version produces a control character rather than a printable one, since true casts to 1.
Example
println("(65).tochar() =", (65).tochar())
println("(65).tochar() == (65 + 256).tochar() =", (65).tochar() == (65 + 256).tochar()) // the (char) cast wraps mod 256
println("(65).tochar().len() =", (65).tochar().len())Output:
(65).tochar() = A
(65).tochar() == (65 + 256).tochar() = true
(65).tochar().len() = 1See also
tostring | Converts the integer to its decimal string form. |
tochar | Converts the float to a one-character string, treating it as a character code. |
tochar | Converts the bool to a one-character string, treating it as a character code. |
| integer | class index |