DOC PREVIEW
TRINITY CSCI 1320 - Intro to C and Binary Numbers

This preview shows page 1-2-3-4 out of 13 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1Intro to C and Binary Numbers8/27/20072Opening Discussion■Let's look at three answers to the interclass question. What are the steps in building a C program?■Do you have any questions about the class based on what we covered last time?3Linux Command Line■Let's all log into the machines and spend a few minutes getting used to the Linux command line.■The PDF file on the web lists a number of different commands in Linux.■The Linux directory structure is just like the folder structure you are used to in Windows. We will navigate it with text commands instead of clicking.■Tab completion is your friend as are up and down arrows.■Command-line execution allows multiple arguments.■The man command will give you the “manual page” entry for any command. This also works for C-library routines as we will see later.4vi■When you are programming you can use any text editor that you want to. Text editors, unlike word processors, edit and save straight text. For comparison, open a .doc file in notepad to see all the extra stuff that Word throws into a file.■I use vi and teach it in this class. It is a powerful programming editor that is ubiquitous on Linux/Unix systems.■Start vi by entering vi and the name of the file you want to edit on the command line.■There are two modes in vi. You start off in command mode. Several commands put you an editing mode. Esc goes back to command mode.5Simple C Program■Lets go into vi together and edit our first program. We will call it hello.c. All of your C programs will be in files that end with .c.6Structure of a C Program■All of your C programs will have several parts.■The top part is pre-processor directives. These begin with a # sign. They are handled in a processing step before the compilation of the program.■Next you can declare global identifiers. I will strongly limit the use of global variables in this class and generally code in a way where you won't use this section.■Below the global identifiers are your methods. Your book puts main as the first method. I will make it last.7Comments■Comments are pieces of text that are thrown out when a program is compiled. These are things you put in for the benefit of humans.■You will want to put your name and a pledge of your code in a comment at the top of each assignment.■Standard C comments are text between /* and */. They can span multiple lines.■C99 allows C++ style single-line comments of the form //. If you use these you need to put in an extra compiler flag saying you are using the C99 standard. I generally won't do this.8Identifiers■Many of the things you put in your C programs will need names. These names are called identifiers and they have certain rules.■Identifiers can contain letters, numbers, and underscores. The first character can't be a number.■C is case sensitive so IDENT and ident are two different identifiers in C.■Identifiers beginning with an underscore are typically used by the system so we won't name anything that way.■I will typically follow the “camel” naming scheme.9Compiling and Executing■We compile our programs with the gcc compiler. Simply specify gcc and the name of the .c file you want to compile.■Many different options can be specified as well. I recommend including -Wall and -pedantic for stronger error checking. If you want to use C99 features use -std=c99.■By default this will make an executable file called a.out that you can run. The -o option allows you to specify a different name to use for the executable.10Binary Numbers■We like to use the decimal (base 10) number system, but numbers can be done in any positive integer base.■Because of the simplicity in making the electronics, computers typically use a binary (base 2) system.■In binary each digit is a power of two and the will have either a 0 or a 1 in it.11Converting Decimal to Binary■One way to convert binary to decimal is to find the largest power of two smaller than the number and subtract that out. That will be a one bit. Each power of two you skip is a zero bit.■Many people prefer the “divide by two” method. I'll write it here as an algorithm.while(n>0)➔if(n is odd) write a 1➔else write a 0➔Divide n by 2 throwing away fraction■This second method is related to bit shifting which we will talk about next week.12Hexadecimal and Octal Numbers■Computers might work in binary, but writing numbers with only 1s and 0s can be a real pain.■Hexadecimal (base 16) and octal (base 8) are common substitutes. They are closer to binary, but don't take nearly so many digits.■Hex numbers have 0-9 and A-F. Octal contains only 0-7.■Converting from binary to hex or octal is as simple as grouping together bit.■Starting at the ones bit, group bits in groups of 4 for hex and groups of 3 for octal.13Minute Essay■In what ways can command line processing be superior to GUIs?■Interclass Problem : Convert the following numbers from decimal to binary (8 bit), hex (2 digit), and octal (3 digit). Write your answers on these systems with vi and show some


View Full Document

TRINITY CSCI 1320 - Intro to C and Binary Numbers

Documents in this Course
Functions

Functions

10 pages

Functions

Functions

10 pages

Graphics

Graphics

10 pages

Graphics

Graphics

11 pages

Loops

Loops

4 pages

Loops

Loops

3 pages

Strings

Strings

9 pages

Functions

Functions

10 pages

Loops

Loops

11 pages

Graphics

Graphics

11 pages

Graphics

Graphics

12 pages

Sorting

Sorting

11 pages

Sorting

Sorting

10 pages

Arrays

Arrays

10 pages

Loops

Loops

18 pages

Load more
Download Intro to C and Binary Numbers
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Intro to C and Binary Numbers and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Intro to C and Binary Numbers 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?