Presentation is loading. Please wait.

Presentation is loading. Please wait.

Topic 6A – The char Data Type. CISC 105 – Topic 6A Characters are Numbers The char data type is really just a small (8 bit) number. As such, each symbol.

Similar presentations


Presentation on theme: "Topic 6A – The char Data Type. CISC 105 – Topic 6A Characters are Numbers The char data type is really just a small (8 bit) number. As such, each symbol."— Presentation transcript:

1 Topic 6A – The char Data Type

2 CISC 105 – Topic 6A Characters are Numbers The char data type is really just a small (8 bit) number. As such, each symbol (character) is represented by a number. Typically, this representation is defined by a standard known as ASCII.

3 CISC 105 – Topic 6A Letters The upper-case letters go from ‘A’ which has ASCII value 65 through ‘Z’ which has value 90. Thus: ‘A’ < ‘B’ < ‘C’ < … < ‘X’ < ‘Y’ < ‘Z’ The lower-case letters go from ‘a’ which has ASCII value 97 though ‘z’ which has value 122. Thus: ‘a’ < ‘b’ < ‘c’ < … < ‘x’ < ‘y’ < ‘z’

4 CISC 105 – Topic 6A Letters Notice that the lower-case letters have larger ASCII values than upper-case letters. Thus: ‘A’ < ‘B’ < … < ‘Y’ < ‘Z’ < … < ‘a’ < ‘b’ < … < ‘x’ < ‘y’ < ‘z’ A program can compare char s using less-than, greater-than, etc… operators using the above relationships.

5 CISC 105 – Topic 6A Digits The digits go from ‘0’ which has ASCII value 48 through ‘9’ which has ASCII value 57. Thus: ‘0’ < ‘1’ < ‘2’ < … < ‘7’ < ‘8’ < ‘9’ Notice that each digit does NOT equal its ASCII value. Therefore 3 and ‘3’ are NOT the same.

6 CISC 105 – Topic 6A Other Characters All of the other characters (such as !,@,#,$,%,^,&,*,(,),-,+,=,_) all have ASCII values as well. They can also be compared in the same manner as the letters and digits. However, as these characters do not relate as easily as the letters do to each other, this is more difficult.

7 CISC 105 – Topic 6A Integer Equivalence Notice that the char data type can also be casted, as the int and float type data types can be. Thus, (int)’E’ = 69 (int)’e’ = 101 (int)’3’ = 51

8 CISC 105 – Topic 6A Arithmetic Operations The char data type can also be subjected to arithmetic operations. Thus, ‘A’ + 3 = 68 = ‘D’ ‘h’ - 4 = 101 = ‘e’ ‘3’ * 1 = 51 = ‘3’


Download ppt "Topic 6A – The char Data Type. CISC 105 – Topic 6A Characters are Numbers The char data type is really just a small (8 bit) number. As such, each symbol."

Similar presentations


Ads by Google