Documente Academic
Documente Profesional
Documente Cultură
Keyboard
Microphone
Scanner
Webcam
Printer
Speaker/Headphone
Read Only Memory (ROM): It is the memory that retains its contents
even after the computer is turned off.
Sound Card converts audio signals (microphone or audio tape) which can
be stored as a computer audio file.
Flash Drive
CD-ROM
DVD-ROM
CPU Memory
Input/Output
R1
R2
R3
ALU I
Control Unit
PC
Registers
0000000000000000 01111001
0000000000000010 10010100
0000000000000100 10000000
. .
. .
. .
1111111111111101 11110000
1111111111111110 11100000
1111111111111111 00000111
1000101010111111
Fig. 2.2 Bit pattern
How does computer memory know what type of data a stored bit pattern
represents?
It does not. Computer memory just stores the data as bit patterns.
It is the responsibility of input/output devices or programs to interpret a bit
pattern as a number, text, or some other type of data.
Computer Basics Dr. Yasser Fouda 47
Data inside the computer
In other words, data are coded when they enter a computer and decoded
when they are represented to the user (Fig. 2.3).
By tradition, a bit pattern of length eight is called a byte. This term has also
been used to measure the size of memory or other storage devices.
For example, a computer memory that can store 8 million bits of
information is said to have a memory of 1 million bytes.
Image 1111111 M
Coding 1011000 Decoding Image
O
Audio Coding 1000000 0101001 Decoding Audio
R
Video Coding 1011001 1111111 Decoding Video
Y
Fig. 2.3 Examples of bit patterns 49
Computer Basics Dr. Yasser Fouda
Representing Data
(Text)
A piece of text in any language is a sequence of symbols used to represent
an idea in that language.
For example, the English language uses 26 symbols (A,B,C,,Z) to represent
uppercase letter, 26 symbols (a, b, c,,z) to represent lowercase letters, 10
symbols (0,1,2,,9) to represent numeric characters and symbols (., ?, :, ; ,
,!) to represent punctuation. Other symbols such as the blank, the newline,
and the tab are used for text alignment and readability.
B Y T E
101101 111100 110100 000101
Fig. 2.4 Representing symbols using bit patterns
Computer Basics Dr. Yasser Fouda 51
Representing Data
(Text)
How many bits are needed in a bit pattern to represent a symbol in a
language? It depends on how many symbols are in the set.
The relationship is not linear, it is logarithmic. If you need two symbols the
length is 1 bit (2 2 is 1). If you need four symbols, the length is 2 bits
(2 4 is 2).
Table in the next slide shows the relationship, which you can easily see.
A bit pattern of 2 bits can take four different forms: 00, 01, 10, 11. Each of
these forms can represent a symbol. In the same way, a bit pattern of 3 bits
can take eight different forms: 000, 001, 010, 011, 100, 101, 110, and 111.
Computer Basics Dr. Yasser Fouda 52
Representing Data
(Text)
Number of symbols Bit pattern length
2 1
4 2
8 3
16 4
128 7
256 8
65536 16
Number of symbols and bit pattern length
Computer Basics Dr. Yasser Fouda 53
Representing Data
(Codes)
Different sets of bit patterns have been designed to represent text symbols.
Each set is called a code, and the process of representing symbols is called
coding.
The American National Standards Institute developed a code called ASCII
(American Standard Code for Information Interchange.
This code uses 7 bits for each symbol. This means 128 (27 ) different
symbols can be defined by this code. The full bit patterns for ASCII code are
in the next slide.
Computer Basics Dr. Yasser Fouda 54
Computer Basics Dr. Yasser Fouda 55
Representing Data
(Codes)
Figure 2.5 shows how BYTE is represented in ASCII code.
B Y T E
1000010 1011001 1010100 1000101
Figure 2.5 Representation of the word BYTE in ASCII code
Computer Basics Dr. Yasser Fouda 56
Representing Data
(Codes)
The following highlights some features of ASCII:
1. Uses a 7-bit pattern ranging from 0000000 to 1111111.
2. The first pattern 0000000 represents the null character.
3. The last pattern 1111111 represents the delete character.
4. There are 31 control (nonprintable) characters.
5. The numeric characters (0 to 9) are coded before letters.
Computer Basics Dr. Yasser Fouda 57
Representing Data
(Codes)
6. There are several special printable characters.
7. The uppercase letters (A Z) come before the lowercase letters (a z).
8. The upper- and lowercase characters are distinguished by only 1 bit. For
example, the pattern for A is 1000001; the pattern for a is 1100001. The
only difference is in the sixth bit from the right.
9. There are six special characters between the upper and lower case letters.
Bitmap Vector
Sampling
Quantization
Figure 2.9 Audio representation
0000010000001111 Coding
4 6 4 25 15
Computer Basics Dr. Yasser Fouda 73
Representing Data
(Video)
Video is a representation of images (called frames) in time. A movie is a
series of frames shown one after another to create the illusion of motion.
So, if you know how to store an image inside a computer, you also know
how to store a video; each image or frame is changed to a set of bit patterns
and stored.
The combination of the images represents the video. Note that today video
is normally compressed.
F C E 4
1 1 1 1 1 1 0 0 1 1 1 0 0 1 0 0 Octal
1 7 6 3 4 4
0 1 0 1 1 0 1 Binary number
64 32 16 8 4 2 1 Position values
0 + 32 + 0 + 8 + 4 + 0 + 1 results
45 Decimal number
Figure 3.3 Binary to decimal conversion
Computer Basics Dr. Yasser Fouda 94
Number Representation
(Conversion)
Example: Convert the binary 10011 to decimal.
Solution:
Binary 1 0 0 1 1
weights 16 8 4 2 1
16 + 0 + 0 + 2 + 1
Decimal 19
0 1 2 5 11 22 45
Reminder
1 0 1 1 0 1
Binary
Figure 3.4 Decimal to binary conversion
Computer Basics Dr. Yasser Fouda 97
Number Representation
(Conversion)
Example: Convert the decimal number 35 to binary.
Solution:
0 1 2 4 8 17 35 Decimal
Binary 1 0 0 0 1 1
Now that you know how to transform from decimal system to the binary
system, let u see how to store integers inside a computer.
Integers are whole numbers (i.e., numbers without fraction). For example,
134 is an integer, but 134.23 is not. As another example, -134 is an integer,
but -134.567 is not.
An integer can be positive or negative. A negative integer ranges from
negative infinity to 0; a positive integer ranges from 0 to positive infinity.
Integer
Representation
Unsigned Signed
+0 00000000
-0 10000000
+0 00000000
-0 11111111
The following table shows common ranges for computers today. Note that in
this system there are two 0s: +0 and -0.
In ones complement representation, the leftmost bit defines the sign of the number.
If it is 0, the number is positive. If it is 1, the number is negative.
In twos complement representation, the leftmost bit defines the sign of the number.
If it is 0, the number is positive. If it is 1, the number is negative.
Computer Basics Dr. Yasser Fouda 129
Twos Complement
(Representation)
Example: Store +7 in an 8-bit memory location using twos complement
representation.
Solution: First change the number to binary 111. Add five 0s that there is a total 8
bits, 00000111. The sign is positive, so no more action is needed.
Example: Store -40 in an 16-bit memory location using twos complement
representation.
Solution: First change the number to binary 101000. Add ten 0s so that there is a
total 16 bits, 0000000000101000. The sign is negative, so leave the rightmost 0s up
to the first 1 (including 1) unchanged and complement the rest. The result is
1111111111011000.
Computer Basics Dr. Yasser Fouda 130
Twos Complement
(Representation)
The following table shows how twos complement numbers are stored in two
different computers: one using 8-bit allocation and one using 16-bit
allocation. Decimal 8-bit allocation 16-bit allocation
+7 00000111 0000000000000111
-7 11111001 1111111111111001
+124 01111100 0000000001111100
-124 10000100 1111111110000100
+24760 Overflow 0110000010111000
-24760 Overflow 1001111101001000
Computer Basics Dr. Yasser Fouda 131
Twos Complement
(Representation)
0 00000000
0000 0 +0 +0 +0
0001 1 +1 +1 +1
0010 2 +2 +2 +2
0011 3 +3 +3 +3
0100 4 +4 +4 +4
0101 5 +5 +5 +5
0110 6 +6 +6 +6
0111 7 +7 +7 +7
1000 8 -0 -7 -8
1001 9 -1 -6 -7
1010 10 -2 -5 -6
1011 11 -3 -4 -5
1100 12 -4 -3 -4
1101 13 -5 -2 -3
1110 14 -6 -1 -2
1111 15 -7 -0 -1
Computer Basics Dr. Yasser Fouda 137
Excess System
Another representation that allows you to store positive and negative
numbers in a computer is called the Excess system.
In this system, it is easy to transform a number from decimal to binary, and
vice versa. However, operations on the numbers are very complicated.
The only application in use today is in storing the exponential value of a
fraction. In an Excess conversion, a positive number, called the magic
number, is used in the conversion process. The magic number is normal
21 or (21 -1), where N is the bit allocation.
Computer Basics Dr. Yasser Fouda 138
Excess System
For example, If N is 8, the magic number is either 128 or 127. In the first
case, we call the representation Excess_128, and in the second case, it is
Excess_127.
To represent a number in Excess, use the following procedure:
1. Add the magic number to the integer.
2. Change the result to binary and add 0s so that there is a total of N bits.
Example: Represent -25 in Excess_127 using an 8-bit allocation.
Computer Basics Dr. Yasser Fouda 139
Excess System
Solution: First Add 127 to -25 and get 102. This number in binary is
1100110. Add 1 bit to make it 8 bits in length. The representation is
01100110.
To interpret a number in Excess, use the following procedure:
1. Change the number to decimal.
2. Subtract the magic number from the integer.
Example: Interpret 11111110 if the representation is Excess_127.
Computer Basics Dr. Yasser Fouda 140
Excess System
Solution: First change the number to decimal. It is 254. Then subtract 127
from the number. The result is decimal 127.
0 . 0 0 1
binary
Binary: 0. 1 1 1
Binary: 0. 0 1 1 0 0 1
Examples of normalization
Note that the 1 to the left of the decimal point is not stored; it is understood
Computer Basics Dr. Yasser Fouda 150
Floating-Pointing Representation
(Normalization)
The sign of the number can be stored using 1 bit (0 or 1).
The exponent (power of 2) defines the movements of the decimal point.
Note that the power can be negative or positive. Excess representation is the
method used to store the exponent. The number of bits allocated (N)
defines the range of numbers that a computer can store.
The mantissa is the binary number to the right of the decimal point. It
defines the precision of the number. The mantissa is stored as an unsigned
integer.
1 8 23 a. Single precision
sign Exponent Mantissa
Excess_1023
1 11 52 b. Double precision
sign Exponent Mantissa
Output
Computer Basics Dr. Yasser Fouda 168
Defining Flow Chart Symbols
There are no one definition for flowcharting symbols
Just be sure that when using these symbols you are consistent with their
meaning
oval
Rectangle
Parallelogram
Diamonds
Circle
Login
Yes
No OK?
Start
Applications
Yes
Retry
Notify System
Administrator STOP
Computer Basics No Dr. Yasser Fouda 177
Examples
Example(1): Construct a simple flowchart for two ATM machine one for
withdrawal and one for deposit.
Variable X is assigned a
free address 1000000, and
there is 0
Computer Basics Dr. Yasser Fouda 197
Qbasic (Variable)
The following program sets the X at 15, and then prints the
variable:
X = 15
PRINT X
15
num
VALUE
xYz
abc123
Computer Basics Dr. Yasser Fouda 199
Qbasic (Variable)
You can also use multiple variables in the program:
X = 82
The memory addresses of variables
does not have to be exactly the same Y = 101
Z = 79
PRINT X
PRINT Y
PRINT Z
82
101
79
Computer Basics Dr. Yasser Fouda 200
QBASIC language Contents
The following Contains are used by QBASIC System:
1. Letters of the alphabet(A,B,C,.Z).
2. Digit Numbers ( 0,1,2..9).
3. Characters and Symbols( +,-,*, /, =,^, ( ),<,> , >=,=< ,<>,@,#,!,?,",% ).
4. Special Words ( go to, if , read, print, input,).
forth -,+ Addition and subtraction are performed last and are equal in
order of precedence.
A=S+R^2-S*R/(S+7)
=+ 2
( + 7)
A=P*Q/(C*B)
=
P=A+B*S/J-d
=+
( + )( + ) R=(S+B)*(A+D)/B
=
Computer Basics Dr. Yasser Fouda 209
Library Functions
Each basic interpreter has within it the capability of calculating certain
special functions, some times called library functions.
These functions are indicated by three letters naming the function, fallowed
by argument enclosed in parentheses.
The argument may be either a number, a variable, or a an expression.
In the following table library functions as might be found in most basic
interpreters.
INT(x) The largest integer not exceeding x. Exp(x) The value of e power x
RND(x) Create random number value between 0 and 1. Log(x) The natural logarithm of x ,ln(x)
S= 2 + 3 () S=sin((x*3.14/180)^2)+cos(x*3.14/180)^3
=
and = +4 R=abs(d-s)/n and Y=s*sqr(s)+4
1 Y=(1-exp(x))/(1+exp(x)) and M=log(x)+b*log(y)
= and M=ln(x)+bln(y)
1+
Read A,N$,M$,T
Data 7.4, "address","telephone",66.7
Input X OR Input X
If (x/2)= int(x/2) then print "x is even" If x mod 2 =0 then print "x is even"
If (x/2) < > int(x/2) then Print "x is odd" If x mod 2 < > 0 then print "x is odd"
Solution
X=1
10 S=S+abs((X^2-3*X)/(X+cos(x*3.14/180)^3)))
X=X+1
If X<=10 then 10
A=S^2
Print A
Solution
For x=1 to 30
S=S+x/(x+1)
Next x
Print S
Solution: