I know how to write hexadecimal literal integers (#A3) in Ceylon. I also know how to parse hexadecimal integers in Ceylon.
Integer? integer = parseInteger("A3", 16);
print(integer.string); // 163
How do I go the other way, get the hexadecimal string representation of an integer?
Use the
Integer.parseandInteger.formatfunctions. They both take a radix, which can be used to generate the string of an integer using an arbitrary base (16 for hexadecimal). By defaultformatIntegergenerates the string with lowercase letters. Use theuppercasedproperty on the string if you want the uppercase version.Note that
formatis not an instance method ofInteger; it is a static method, so you can't dointeger.format(16).Also, note that
parsereturns aParseExceptionon failure rather thanNullso that there is more information in that failing case.