Page 779 - Introduction to Programming with Java: A Problem Solving Approach
P. 779

                  APPENDIX 1
   Unicode/ASCII Character Set with Hexadecimal Codes
Java assigns a unique two-byte numerical code value to each character in accordance with the Unicode standard. Since two bytes contain a total of 16 bits, this provides a total of 216 􏰀 65,536 different codes. Chapter 11’s Figure 11.4 describes or shows those characters whose code values lie in the range 0 to decimal 127. In this particular range of code values, Unicode code values coincide exactly with ASCII code values. (ASCII 􏰀 American Standard Code for Information Interchange.)
Hexadecimal numbers use digits that can have one of 16 values. The allowed values are 0 through 9 and
A through F. The A through F values represent the numbers 10 through 15. Figure 11.4 used decimal num-
bers to represent Unicode (and ASCII) code values in the range 0 through decimal 127. However, sometimes
Notice that the hexadecimal code values for the numerical characters ‘1’ through ‘9’ are hexadecimal 31 through hexadecimal 39. Now look at the rest of the ASCII characters in Figure A1.1b. Notice that the code value for the first uppercase letter, A, is hexadecimal 41, and the code value for the first lowercase let- ter, a, is hexadecimal 61. To change case, you can simply add or subtract hexadecimal 20. The people who assigned these codes were “thinking” in hex!
In the columns under “Unicode,” Figures A1.1a and A1.1b also show the Unicode escape sequence for each character. These are what you use if you want to embed within a String any character or symbol that cannot be typed in directly. Each of these Unicode escape sequences puts a \u prefix on a four-place hexadecimal version of the code number. (If necessary, we pad the raw hexadecimal number left with zeros to increase the total number of hexadecimal digits to four.) This format enables the standard Unicode escape sequence to accommodate up to a total of 164 􏰀 65,536 distinct characters or symbols.
Of course there are many other characters and symbols. For more discussion and information, read the material in optional Section 11.12, GUI Track: Unicode. Figure 11.12 displays a sampling of some of the other available characters and symbols. That display was generated by the program in Figure 11.11, and you can modify that program to display the characters for any other range of codes. For all the details on the Unicode standard, see:
http://www.unicode.org/
Apago PDF Enhancer
in this numerical range, and especially at higher numerical values, it’s more convenient to use hexadecimal numbers to represent Unicode values as well as memory locations. To give you a better feeling for how hexadecimal counting works, and to help you find the hexadecimal values for characters in the important ASCII Character Set, Figure A1.1a displays the ASCII characters with hexadecimal numbers shown along- side the corresponding decimal numbers.
745






















































































   777   778   779   780   781