4 ms·
Correct, but there are several things to consider. Due to byte/short/char being promoted to int for any arithmetic, any time you do an operation like char+char
by nayuki 4y ago
Correct, but there are several things to consider.
Due to byte/short/char being promoted to int for any arithmetic, any time you do an operation like char+char→int, you'll still come into contact with signed types and need to continually cast back to char. This problem also occurs in C/C++, and you can typically find that uint16_t * uint16_t → signed int.
Using char to represent numbers (e.g. 16-bit channel values for pixels) instead of text is semantically incorrect. There's no problem if you're just working within Java, but once you get into comparing or porting code across languages, this is a code smell. Just as an example, the range for char in Rust is [0x000000, 0x10FFFF], and this is checked at run time when converting to char; this would be seen as weird from the lens of C/C++/Java where char is just a sequence of bits where all values are allowed.
- dmitrygr 4y ago> this is a code smell Worry not - the only time i ever authored java code was when i was making the world's smallest (still) JVM. You have no reaosn to worry about bad smelling java code using char as uint16 from me :D