Chapter 1
Two’s Complement Form

For signed integers,
the leftmost
bit is used for sign. 0 for positive and 1
for negative.
Ex: Convert the 2’s complement integer
10101100 to
decimal.
Solution:
Find the absolute value of the
integer by
changing each 1 to 0 and each 0 to
1.
01010011
Then add 1 to this number.
01010011
+
1
01010100
01010100 = 64 + 16 + 4 = 84
The original bit string 10101100
represents the decimal number
84
.
FloatingPoint Numbers
 A number with a
decimal point, such
as 8.3194 or 6.34 X 10^20
(scientific
notation)
.
6.34 =>
( Mantissa )
10 =>
(Base)
20 =>
(Exponent)
IEEE – singleprecision standard
represents a floatingpoint number in one
32bit word.
1
st
bit
 (s) represents the sign bit.
0 => (+), 1 => ()
29 bits
 are interpreted as an
unsigned integer e’.
If e’≠ 0, the
exponent is defined as e’ – 127.
If
e’ = 0, the exponent is defined as
126.
1032 bits
– are interpreted as the
value
m’ = 0.b
1
b
2
….b
23
in base 2,
that is
m’ = b
1
*2
1
+ b
2
*2
2
+ … + b
23
*2
23
So.
If e’ ≠ 0, the mantissa is 1+m’,
and the number represented is:
(1)
s
* (1+m’ ) * 2
(e’127)
If e’ = 0, the mantissa is m’, and
the number represented is:
(1)
s
* m’ * 2
126
EX: 0
10101100
1001101000000000000
(spaces included for clarity).
The leading 0 indicates a (+)
num.
10101100 = 172.
so e’ = 172  127 = 45
.
m’= 1*2
1
+ 1*2
4
+ 1*2
5
+ 1*2
7
=.578125
and the number represented is
1.578125 * 2
45
Chapter 2
preprocessor directive
– request some action
before
the program is actually translated into
machine code. #include <stdio.h>
header file
– files with .h extensions.
functions
– a C program consists of one or
more functions,
exactly one of which is called main
.
variables
– all C variables must be defined,
which in C is to
request storage for a particular data type.
identifier
– is the official word for name in a
highlevel language.
An identifier in C must
satisfy to following requirements.
1.
It must start with a letter or an
underscore.
2.
It must consist of only letters, digits 0
9, and the underscore.
3.
It must not be a
keyword
such as
int
or
while
.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Documentwhile statement
while (expression)
action
EX:
int x;
x = 0;
while ( x != 2)
x = x + 1;
printf ( “x = %d \n”, x);
* the printf is not included in the while
construct.
If no {} are used, only the 1
st
statement after while is executed.
do while statement
do
action
while (expression);
* similar to while statement, except the body of
the loop is always executed at least once.
EX:
do {printf ( “Enter a positive
integer: “);
scanf ( “%d”, &x);}
while ( x <= 0 );
* This will keep prompting the user to enter a
positive integer until they do.
if statement
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 Staff
 ASCII, scanf, char c

Click to edit the document details