This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
The code makes a digit - from 0 to 9 of a char. The character is represented inside the computer as a series of 0s and 1s. Using ASCII as an example: the character '0' is represented as 48 (decimal), and as with all character sets in use, the digits are arranged sequentially - '1' is 49, '2' is 50 ...
when you subtract '0' from it, you get for '0': '0' - '0' which equates to 48 - 48 which is 0; for '1', '1' - '0' which is 49 - 48 --> 1.
Java uses unicode, but the principle is the same, and furthermore the code doesn't rely on a specific character set as long as the digits are represented sequentially.