ASCII

Notes

Everything that goes on under the hood of a computer is done in binary -- the language of 0s and 1s.

In order to use binary to express alphabetic, numeric, and other characters, we need some kind of mapping between characters and numbers.

ASCII is an encoding system that maps alphabetic, numeric, and other characters to numbers.

For example, uppercase 'A' is represented by the number 65, and lowercase 'a' is represented by the number 97.

The following will print out:

32

b

B

C

a

This program will print the uppercase letters of the alphabet in reverse alphabetical order.

Note how you can use 'Z' instead of the magic number 90, and 'A' instead of the magic number 65. Definitely makes the code more readable!

This program converts each letter of a lowercase string to uppercase.

Take some time to think about why adding ('A' - 'a') to a lowercase letter capitalizes it.

Slides ( / )

study50 slide
study50 slide
study50 slide
study50 slide
study50 slide

Uppercase or Lowercase?

Prerequisites:

Complete the following program that prompts the user to enter an alphabetical character and determines whether the character is uppercase or lowercase.

jharvard@run.cs50.net (~): ./a.out
Please enter an alphabetical character: Z
Thanks for the uppercase letter!

Try out some pseudocode here!
#include <cs50.h>
#include <stdio.h>

int main (int argc, string argv[])
{
    // Collect user input
    printf("Please enter an alphabetical character: ");
    char c = GetChar();

    // If letter is uppercase
    if (/* TODO */)
        printf("Thank you for the uppercase letter!\n");

    // If the letter is lowercase
    else if (/* TODO */)
        printf("Thank you for the lowercase letter!\n");

    // If not an alphabetical character
    else
        printf("You did not enter an alphabetical character!\n");
}

Bitwise Capitalization

Write a program that prompts the user to enter a lowercase letter (be sure the user provides the desired input!). Use bitwise operators to capitalize the letter.

jharvard@run.cs50.net (~): ./a.out
Please enter a lowercase letter: b
B

Try out some pseudocode here!
#include <cs50.h>
#include <stdio.h>

int main(int argc, string argv[])
{
    // TODO
}

Myspace

Prerequisites:

Write a program that prompts the user for a message, and then outputs the message with its first letter capitalized, with all letters in alternating case, as per the sample output below. For simplicity, you may assume that the user will only input lowercase letters and spaces.

jharvard@run.cs50.net (~): ./a.out
thanks for the add
ThAnKs FoR tHe AdD

Try out some pseudocode here!
#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>

int main (int argc, string argv[])
{

	// TODO

}

Videos

study50 video thumbnail

Wednesday, Week 0

Introduction to ASCII
study50 video thumbnail

Nate's ASCII Short

Nate gives a general overview