|
[61] One fundamental component of a computer's handling of alphanumeric data is its character set. A character set is, not surprisingly, the set of all the characters that the computer can process and display. (Each character generally has a key on the keyboard to enter it and a bitmap on the screen which displays it.) A character set consists of letters, numbers, punctuation, etc., but the point of this discussion is not so much what the characters are but that we have to be careful to distinguish between characters, strings, and numbers. |
[61] One fundamental component of a computer's handling of alphanumeric data is its character set. A character set is, not surprisingly, the set of all the characters that the computer can process and display. (Each character generally has a key on the keyboard to enter it and a bitmap on the screen which displays it.) A character set consists of letters, numbers, punctuation, etc., but the point of this discussion is not so much what the characters are but that we have to be careful to distinguish between characters, strings, and numbers. |
[62] A character is, well, a single character. If we have a variable which contains a character value, it might contain the letter `A', or the digit `2', or the symbol `&'. : Ein Zeichen ist: Ein einzelnes Zeichen. Eine Variable, die ein Zeichen speichert, könnte z.B. den Buchstaben 'A' oder die Ziffer '2' oder das Symbol '&' als Wert enthalten. |
[62] A character is, well, a single character. If we have a variable which contains a character value, it might contain the letter 'A', or the digit '2', or the symbol '&'. : Ein Zeichen ist, nun ja, ein einzelnes Zeichen. Eine Variable, die ein Zeichen speichert, könnte z.B. den Buchstaben 'A' oder die Ziffer '2' oder das Symbol '&' als Wert enthalten. |
[63] A string is a set of zero or more characters. For example, the string "and" consists of the characters `a', `n', and `d'. The string "K2!" consists of the characters `K', `2', and `!'. The string "." consists of the single character `.', and the empty string "" consists of no characters at all. Not to belabor the point, but the string "123" consists of the characters `1', `2', and `3', and the string "4" consists of the single character `4'. : Eine Zeichenkette ist eine Folge von 0 oder mehr Zeichen. Beispielsweise besteht die Zeichenkette "oder" aus den Zeichen 'o', 'd', 'e' und 'r'. Die Zeichenkette "K2!" besteht aus den Zeichen 'K', '2' und '!'. Die Zeichenkette "." besteht nur aus einem einzigen Zeichen '.' (trotzdem ist die Zeichenkette "." nicht identisch mit dem Zeichen '.'). Die leere Zeichenkette "" als Sonderfall enthält überhaupt keine Zeichen. Als abschließende Beispiele: Die Zeichenkette "123" besteht aus den Zeichen '1', '2' und '3', und die Zeichenkette "4" besteht aus dem einen Zeichen '4'. |
[63] A string is a set of zero or more characters. For example, the string "and" consists of the characters 'a', 'n', and 'd'. The string "K2!" consists of the characters 'K', '2', and '!'. The string "." consists of the single character '.', and the empty string "" consists of no characters at all. Not to belabor the point, but the string "123" consists of the characters '1', '2', and '3', and the string "4" consists of the single character '4'. : Eine Zeichenkette ist eine Folge von null oder mehr Zeichen. Beispielsweise besteht die Zeichenkette "und" aus den Zeichen 'u', 'n', und 'd'. Die Zeichenkette "K2!" besteht aus den Zeichen 'K', '2' und '!'. Die Zeichenkette "." besteht nur aus einem einzigen Zeichen '.' (trotzdem ist die Zeichenkette "." nicht identisch mit dem Zeichen '.'). Die leere Zeichenkette "" als Sonderfall enthält überhaupt keine Zeichen. Als abschließende Beispiele: Die Zeichenkette "123" besteht aus den Zeichen '1', '2' und '3', und die Zeichenkette "4" besteht aus dem einen Zeichen '4'. |
[64] The last two examples illustrate some important and perhaps surprising or annoying distinctions. The character `4' and the string "4" are conceptually different, and neither of them is quite the same as the number 4. The string "123" consists of three characters, and it looks like the number 123 to us, but as far as the computer is concerned it is just a string. The number 123 is, when used for ordinary numeric purposes, not represented internally as a string of three characters (instead, it is typically represented as a 16- or 32-bit integer). When we have a string which contains a numeric value which we wish to manipulate as a number, we must typically ask for the string to be explicitly converted to that number somehow. Similarly, we may have reason to convert a number to a string of digits making up its decimal representation. : Die letzten beiden Beispiele zeigen einen wichtigen und möglicherweise überraschenden und ärgerlichen Unterschied: Das Zeichen '4' und die Zeichenkette "4" sind nicht dasselbe, und beide sind wiederum verschieden von der Zahl 4. Die Zeichenkette "123" besteht aus 3 Zeichen; sie sieht aus wie die Zahl 123, aber für den Rechner ist es keine Zahl sondern eine Zeichenkette, und er speichert es auch nicht wie einen Zahlenwert ab. Ein Zahlenwert für Berechnungen würde nicht in Form der einzelnen Ziffern gespeichert, sondern typischerweise als binäre 16-Bit-Zahl oder 32-Bit-Zahl. Eine Zeichenkette aus Ziffern, die als Zahlenwert aufgefasst werden soll, muss zuvor umgewandelt werden. Ebenso muss ein numerischer Wert in eine Zeichenkette umgewandelt werden, wenn er gedruckt oder am Bildschirm ausgegeben werden soll. |
[64] The last two examples illustrate some important and perhaps surprising or annoying distinctions. The character '4' and the string "4" are conceptually different, and neither of them is quite the same as the number 4. The string "123" consists of three characters, and it looks like the number 123 to us, but as far as the computer is concerned it is just a string. The number 123 is, when used for ordinary numeric purposes, not represented internally as a string of three characters (instead, it is typically represented as a 16- or 32-bit integer). When we have a string which contains a numeric value which we wish to manipulate as a number, we must typically ask for the string to be explicitly converted to that number somehow. Similarly, we may have reason to convert a number to a string of digits making up its decimal representation. : Die letzten beiden Beispiele zeigen einen wichtigen und vielleicht überraschenden oder ärgerlichen Unterschied: Das Zeichen '4' und die Zeichenkette "4" sind konzeptionell verschieden, und beide sind wiederum verschieden von der Zahl 4. Die Zeichenkette "123" besteht aus 3 Zeichen; für uns sieht sie aus wie die Zahl 123, aber für den Rechner ist es keine Zahl sondern einfach nur eine Zeichenkette [und er speichert sie auch nicht wie einen Zahlenwert ab]. Ein Zahlenwert für Berechnungen würde nicht in Form der einzelnen Ziffern gespeichert, sondern typischerweise als binäre 16-Bit-Zahl oder 32-Bit-Zahl. Eine Zeichenkette aus Ziffern, die als Zahlenwert aufgefasst werden soll, muss zuvor umgewandelt werden. Ebenso muss ein numerischer Wert in eine Zeichenkette umgewandelt werden, wenn er gedruckt oder am Bildschirm ausgegeben werden soll. [65] We may also find ourselves needing to convert back and forth between characters and the numeric codes which are assigned to each character in a character set. (For example, in the ASCII character set,the character 'A' is code 65, the character '.' is code 46, and the character '4' is, perhaps surprisingly, code 52.) |
[65] We may also find ourselves needing to convert back and forth between characters and the numeric codes which are assigned to each character in a character set. (For example, in the ASCII character set,the character `A' is code 65, the character `.' is code 46, and the character `4' is, perhaps surprisingly, code 52.) |
[[Link]Next[Url=DiesesWiki:SteveSummit/Teil11]] |
[[Link]Next[Url=DiesesWiki:SteveSummit/Teil11]] |
Characters, Strings, and Numbers