Using ssize_t vs int

There’s no guarantee in the POSIX standard that sizeof(int) >= sizeof(ssize_t), nor the other way around. Typically ssize_t is larger than int, but the safe and portable option in C99 is to use intmax_t instead for the argument and the return value. The only guarantees you have wrt. the relationship between int and ssize_t are: int can store values of at least the range [-2^15 … … Read more

Converting characters to integers in Java

The java.lang.Character.getNumericValue(char ch) returns the int value that the specified Unicode character represents. For example, the character ‘\u216C’ (the roman numeral fifty) will return an int with a value of 50. The letters A-Z in their uppercase (‘\u0041’ through ‘\u005A’), lowercase (‘\u0061’ through ‘\u007A’), and full width variant (‘\uFF21’ through ‘\uFF3A’ and ‘\uFF41’ through ‘\uFF5A’) forms have numeric values from 10 through 35. This is … Read more

How to convert a char to a String?

You can use Character.toString(char). Note that this method simply returns a call to String.valueOf(char), which also works. As others have noted, string concatenation works as a shortcut as well: But this compiles down to: which is less efficient because the StringBuilder is backed by a char[] (over-allocated by StringBuilder() to 16), only for that array to be defensively copied by the resulting String. String.valueOf(char) “gets in … Read more