Simple IO
Eric McCreath
putchar
We have looked at printf and it is a simple way of outputting to
standard out . If you want something even simpler (and a little
more control) then putchar gives you a way of outputting a single
character at a time.
Below i
Number Systems
Eric McCreath
Decimal
Decimal is the most commonly used number system.
We are so familiar with decimal that we can both understand what
numbers represent and perform operations on decimal numbers
without much thought.
Decimal is base 10 and
Structure of a c program
Eric McCreath
Basic structure
The basic structure of a c program includes:
comments
includes
prototypes
global variables
constants
functions
main function
2
Comments
Comments provide a way for those reading your code to
understand
Tools for viewing and editing binary data
Eric McCreath
cat and less
The cat command will concatenate a list of files and print the
result to standard output. It provides a quick way of viewing the
contents of a single ASCII file.
In the example below (an
Fixed and Floating-point Numbers
Eric McCreath
Fractional binary numbers
Remember how the meaning of the digits in a binary number is
defined:
Note the binary radix point
For example, the binary number:
means
2
Binary
Converting a fractional number (repre
Introduction to Computer Systems
Hello World and gcc
Eric McCreath
Hello World
The classic first program:
#include<stdio.h>
void
main() cfw_
printf("Hello World\n");
Or
#include<stdio.h>
int
main() cfw_
printf("Hello World\n");
return 0;
to compile and
Functions and Flow Control
Eric McCreath
Why Functions?
Functions provide a way of grouping code that achieves a
particular computational task.
This has a number of advantages for the programmer including:
They can create "black boxes" (which are the func
Variables
Eric McCreath
The Variable
Variables vary. Well mostly. Variables provide a reference to
some stored information. In c this is almost always a location in
memory (sometimes the data of a variable may be just in a
register).
Primary Memory
To set
Data types and printf
Eric McCreath
Learning C
It is difficult to present material on C programming such that
ensuing content purely builds on previous content. Therefore, we
simply jump into the C programming language and then focus on
different aspects
Expressions
Eric McCreath
Expressions on integers
There is the standard set of interger operators in c.
We have:
y
y
y
y
y
y
=
=
=
=
=
=
4 +
7 3 *
x /
x %
-x;
7;
3;
x;
3;
3;
/
/
/
/
/
/
add
subtract
multiply
integer divide
integer remainder
integer negate
Negative Numbers and Binary
operations
Eric McCreath
Binary Addition
Adding binary numbers is very similar to how you would add
large decimal numbers in primary school
It involves positioning the numbers such that the columns line
up in their powers,
Then
Bit Basics
Eric McCreath
Bit Basics
A bit (Binary digIT) is single unit of binary storage. A bit is
normally grouped with other bits to represent data or information.
4 bits form a nibble
8 bits form a byte (e.g. 10100001 or 0xA1 in hex)
Bytes are grouped
COMP2300/COMP6300
Introduction to Computer Systems
2016
Eric McCreath
Acknowledgement
"We acknowledge and celebrate the First Australians on whose
traditional lands we meet, and pay our respects to the elders of the
Ngunnawal people past and present."
- T