Characters must also be encoded in binary - Google Docs

0 downloads 171 Views 336KB Size Report
AAS. Example #2. Converts a lowercase string to uppercase. 1. char name[] = "milo";. 2. for (int i = 0, j = strlen(name)
Characters must also be encoded in binary

ASCII maps characters to numbers

AAS ASCII Math What will print? 1. 2. 3. 4. 5.

printf("%d\n", 'a' – 'A'); printf("%c\n", 'B' + ('a' – 'A')); printf("%c\n", 'b' – ('a' – 'A')); printf("%c\n", 'B' + 1); printf("%c\n", ('z' – 'a' + 1) % 26 + 'a');

AAS #1 Example Prints Z through A

1.

for (int i = 'Z'; i >= 'A'; i--) printf("%c\n", i);

Example #2

AAS Converts a lowercase string to uppercase

1. 2.

char name[] = "milo";

3.

f

for (int i = 0, j = strlen(name); i < j; i++) name[i] = name[i] + ('A' - 'a');