Unsigned short in Java

You can’t, really. Java doesn’t have any unsigned data types, except char. Admittedly you could use char – it’s a 16-bit unsigned type – but that would be horrible in my view, as char is clearly meant to be for text: when code uses char, I expect it to be using it for UTF-16 code … Read more

Why must a short be converted to an int before arithmetic operations in C and C++?

If we look at the Rationale for International Standard—Programming Languages—C in section 6.3.1.8 Usual arithmetic conversions it says (emphasis mine going forward): The rules in the Standard for these conversions are slight modifications of those in K&R: the modifications accommodate the added types and the value preserving rules. Explicit license was added to perform calculations … Read more