CS 211 - Part I
CS 211 - Part I
2017/2018
Data represents facts about entities. It can also be defined as unprocessed information.
Example of data is: age, registration number, tests score of students. Another example is
Records of daily sales of a supermarket.
Data can be in textual format. Numbers or digits (eg 1, 6, 25 etc), alphabets (eg Musa, Ali,
Joy etc), alpanumeric (eg, Alice&23;Bob_1980). Data can be in non-textual format such as
Audio/Sound, pictures and video.
Digital Computers use representation based on a binary system. The binary number system
has TWO digits 0 and 1. Any data whether textual or non-textual, is stored in computer
memory as a sequence of binary digits (bit).
The main memory of computer (RAM) is logically structured as a linear array of cells, each
of which stores string of binary digits (0s and 1s) representing data or instruction. The
memory cells are organized into group of bits often called word of fixed size. For easy
access, each of the memory cells is associated with a unique address. The addresses are
consecutive numbers starting from 0 specifying successive memory locations. The CPU can
read and write to those memory locations or cells.
Technically, bit is electrical states of off or on OR high or low in computer circuitry. Each
binary digit is represented by an electrical pulse. The bit ‘1’ represents the presence of
electrical pulse. The bit ‘0’ represents the absence of electrical pulse. Therefore, the
representation of individual character is a series of electrical pulse.
Bit is the most basic unit of information in digital computers. A bit is represented in digital
computers by physical quantities called signals. Electrical signals such as voltage exist
throughout the computer in either one of two recognizable states described above. The
manipulation of binary information is done by logic circuits called gates. Gates are blocks of
hardware that produce signals of binary 1 or 0 when input logic requirements are satisfied. A
variety of logic gates are used in digital systems. Each gate has distinct graphic symbol and
its operation can be described by means of algebraic expression.
Manufacturers of computer storage devices express the capacity of such devices in terms of
the number of bytes they can hold. Today, even the bandwidth for internet connectivity is
measured in bytes.
2
ATBU Bauchi, DMS_ CS211 Note. 2017/2018
1 Byte = 8 bits
1KB = 210 bytes = 1024 bytes i.e, thousands of bytes
1MB = 210 KB = 1024KB = (1024 × 1024 bytes) i.e, millions of bytes
1GB = 1024MB i.e, billions of bytes
1TB = 1024GB
Exercise: Work out the number of bytes of a memory card whose capacity is 1.5GB.
Memory cards, Flash drives, RAM and Hard Disk Drive of modern computers are
available usually in gigabytes.eg 4GB RAM, 500GB
Beside binary number system, the Octal (base 8) and Hexadecimal (base 16) are important
in digital computer work. Octal and Hexadecimal number systems are used because they
provide nice way to abbreviate long string of binary digits. The word size (word length) may
abbreviated with octal digits (each octal digit represents three binary digits), or with
hexadecimal digits (each octal digit represents four binary digits).
Octal is sometimes used in computing instead of hexadecimal; perhaps most often in modern
times in conjunction with file permissions under Unix systems (see chmod). It has the
advantage of not requiring any extra symbols as digits (the hexadecimal system is base-16
and therefore needs six additional symbols beyond 0–9). While Octal is another type of
digital numbering system, it is little used these days instead Hexadecimal Numbering System
is commonly used as it is more flexible. Two hexadecimal digits exactly specify one byte.
NUMBER SYSTEM
A number system of base r is a system that uses distinct symbols for r digits. The number
systems that are of interest in Computer Science are binary and hexadecimal. To distinguish
between different bases, the base is written as a subscript.
Base System
Decimal The decimal system is base 10. The digits in decimal system are: 0, 1, 2,
3, 4, 5, 6, 7, 8, 9. Decimal number system is used by humans in their
daily activities to express quantities.
Binary Binary is base 2. There are only 2 digits 0, and 1 called binary digits
(bits). Example of number expressed in binary is:
1011012
3
ATBU Bauchi, DMS_ CS211 Note. 2017/2018
Octal Octal is base 8. It is also used for representing binary digits. There are 8
digits: 0, 1, 2, 3, 4, 5, 6, 7. Example of number expressed in octal is:
5628
Hexadecimal Hexadecimal is base 16. It is very useful for representing binary data
concisely! There are 16 digits 0 to 15:
.
F2EA16
The general idea behind positional numbering systems is that a numeric value is represented
through increasing powers of a radix (or base). This is often referred to as a weighted
numbering system because each position is weighted by a power of the radix.
The basic idea is that a numeric value is represented through increasing power of a radix or
base. Each position is weighted by a power of the radix.
The following table shows the position and weight.
n …. 3 2 1 0 POSITION
n 3 2 1 0
Binary 2 …. 2 2 2 2 =1
n 3 2 1
Octal 8 …. 8 8 8 80 = 1 WEIGHT
n 3 2 1 0
Hexa 16 ….. 16 16 16 16 = 1
4
ATBU Bauchi, DMS_ CS211 Note. 2017/2018
Generally, with N bits, the range of unsigned integers that can be represented is 0 to 2 N – 1.
For example, 4 bits can represent the decimal values 0 to 15, while 8 bits can represent the
values 0 through 255. The range of values that can be represented by a given number of bits
is extremely important when doing arithmetic operations on binary numbers.
Fractions in any base system can be approximated in any other base system using negative
powers of a radix. Radix points separate the integer part of a number from its fractional part.
In the decimal system, the radix point is called a decimal point. Binary fractions have a
binary point.
Fractions that contain repeating strings of digits to the right of the radix point in one base
may not necessarily have a repeating sequence of digits in another base. For instance, 2/3 is a
repeating decimal fraction, but in the ternary system it terminates as 0.23 (2×3-1 = 2×1 3).
We can convert decimal fractions to base n using method analogous to the division-remainder
methods for converting integers. However, here we repeatedly multiply the fractional part by
n until the result is 0. The integer part of the multiplication process is then picked and read
from top to bottom. The following is an example
5
ATBU Bauchi, DMS_ CS211 Note. 2017/2018
1. 5 0 0
x 2
1. 0 0 0
2310 = 101112
Therefore, 23.75010 = 10111.112
Reading from top to bottom, 0.3437510 = 0.0101 to
four binary places
Conversion from Base n to Decimal
To convert a given number expressed in base n to decimal, we used the positional numbering
system (also called weighted numbering system) described above.
Example 10: Convert 1012 to decimal
Solution
(1×22) + (0×21) + (1×20) => 4 + 0 + 1 = 5
Therefore, 1012 = 510
Example 11: Convert 10011002 to decimal
Solution
(1×26) + (0×25) + (0×24) + (1×23) + (1×22) + (0×21) + (0×20)
64 + 0 + 0 + 8 + 4 + 0 +0 = 76
Therefore, 10011002 = 7610
Example 12: Convert 23E16 to decimal
Solution
(2×162) + (3×161) + (14×160) => 512 + 48 + 14 = 574
Therefore, 23E16 = 57410
Alternatively, you can convert 23E16 to binary and then convert the binary to decimal
Example 13: Convert 10101.10112 to decimal
Solution
(1×24) + (0×23) + (1×22) + (0×21) + (1×20) + (1×2-1) + (0×2-2) + (1×2-3) + (1×2-4)
16 + 0 + 0 + 4 + 0 + 1 + + 0 + + = 21 + 0.5 + 0.125 + 0.0625 = 21.6875
Therefore, 10101.10112 = 21.687510
Note: the numbering of position of the fractional part starts from -1
6
ATBU Bauchi, DMS_ CS211 Note. 2017/2018
To convert binary numbers to hexadecimal, organise the bits into group of 4 and replace them
with their hexadecimal equivalent. We start grouping the bits from the LSB (Least Significant
Bit) or the rightmost bit.
Example 14: Convert 10111012 to hexadecimal
Solution
Start counting the digits from the right most bit (least significant bit).
0101 1101
01012 = 5, and 1101 = 13 => D
Solution
Solution
Start counting the digits from the right most bit (least significant bit).
7
ATBU Bauchi, DMS_ CS211 Note. 2017/2018
Exercise
Given the following bits 1100100111012, what is the octal and hexadecimal equivalent?
Answer: 62358 and C9D16 Please verify.
One’s complement
To represent signed integers using one’s complement, the following steps are essential
i. Obtain the binary equivalent of the integer, and
8
ATBU Bauchi, DMS_ CS211 Note. 2017/2018
Solution
We first find the binary equivalent of 13.
+13 = 00001101
Flip the bits. That is, change 1 to 0 and 0 to 1.
-13= 11110010
Like signed magnitude, one’s complement is not used on modern computers.
Two’s Complement
To represent a signed number using two’s complement,
i. Obtain the binary equivalent of the integer, and
ii. Flip the bits (change 1 to 0, and 0 to 1).
iii. Add 1 to the flipped bits
iv. If there is any bit ‘carried’ from the MSB, we simply discard or ignore it.
Example 22: Use 8 bits and two’s complement method to represent -1610.
Solution
We first find the binary equivalent of 16.
+1610 = 000100002
Flip the bits. That is, change 1 to 0 and 0 to 1.
-1610 = 11101111 + 1 = 111100002
Unlike signed magnitude and one’s complement methods, in two’s complement there is only
one representation of 0.
+0 = 00000000.
Flip the bits. That is, change 1 to 0, and 0 to 1
-0 = 11111111
Add 1 to the flipped bits. => 11111111 + 1
=> 1 00000000.
Note that there is a bit ‘carried’ out of the MSB (8th bit position). We simply discard it.
Modern computer adopted the two’s complement method to perform arithmetic operations.
9
ATBU Bauchi, DMS_ CS211 Note. 2017/2018
The Institute of Electrical and Electronic Engineers (IEEE) published a standard called IEEE-
754 for representing floating point numbers. The IEEE standard specifies the number of bits
to be used when representing floating point numbers. The IEEE-754 sardard I divided into 2.
i. IEEE Single precision – It uses 32 bits. 8 bits for exponent, 23 bits for mantissa
(significand) and 1 bit for the sign. Therefore, single precision uses an excess 127 bias
over 8 bit exponent.
ii. IEEE double precision – It uses 64 bits. 11 bits for exponent, 53 bits for the mantissa
(significand) and 1 bit for the sign. The bias is 1023.
10
ATBU Bauchi, DMS_ CS211 Note. 2017/2018
CHARACTER REPRESENTATION
In the previous sections, we have seen how numbers are represented in computer. Obviously
numbers are not the only characters that computer represents. In addition to numbers,
computers also represent lower and upper case letters (a-z ; A-Z), special symbols such as
punctuation marks, &, <, etc, these all together are referred to alphanumeric. Alphanumeric
data are represented by assigning a unique binary code or sequence of bits to represent each
character. As character is entered through keyboard or any other input device is converted
into binary code. The encoding schemes used to represent character in computer system are
11
ATBU Bauchi, DMS_ CS211 Note. 2017/2018
ASCII
ASCII (pronounced "AS-key"), defines codes for control characters, digits, letters (upper-
and lowercase), special characters (such as $ and #), and the space character. It has two
versions. The first version uses 7-bit code to represent 27 = 128 different for characters. The
second version, which is more common, uses 8 bits to represent 256 different characters. For
all practical purposes an 8 bit code is used. The eight bit which the MSB is used for parity. A
parity bit is turned “on” or “off” depending on whether the sum of the other bits in the byte is
even or odd. Parity is the most basic of all error detection schemes. For example, if we decide
to use even parity and we are sending an ASCII A, the lower 7 bits are 1000001. Because the
sum of the bits is even, the parity bit would be set to off and we would transmit 0100 0001.
Similarly, if we transmit an ASCII C, 100 0011, the parity bit would be set to on before we
sent the 8-bit byte, 1100 0011.
The ASCII representation has been adopted as a standard by the U.S. government and is
found in a variety of computers, particularly minicomputers and microcomputers.
Like EBCDIC, the 8 bits used to represent a character are partitioned into two groups; zone
bits and numeric bits. The following table shows the zone and numeric bits for some
character.
ASCII – 8 codes
Characters Decimal Zone bits Numeric bits
A–O 65 – 79 0100 0001 – 1111
P–Z 80 – 90 0101 0000 – 1010
a–o 97 – 111 0110 0001 – 1111
p–z 112 – 122 0111 0000 – 1010
0–9 48 – 57 0011 0000 – 1001
Comprehensive list of ASCII characters set can be found on the internet – specifically,
Wikipedia. https://en.wikipedia.org/wiki/ASCII
Example 27: Using ASCII, what are the bits that represent CS232
Method I
C => 3 = 0011, zone bits = 0100, => 0100 0011
S => 3 = 0011, zone bits = 0101 => 0101 0011
12
ATBU Bauchi, DMS_ CS211 Note. 2017/2018
13
ATBU Bauchi, DMS_ CS211 Note. 2017/2018
format stores the patterns of pixels. By storing just the patterns and not every pixel, JPEG and
GIF file formats are often many times less bytes than a corresponding bitmap format of the
graphic would be. This makes JPEG and GIF much better suited to storing on the small flash
cards of digital cameras or for downloading over the relatively slow Internet.
Representation of Sound
Sound occurs naturally as an analog wave. However, all data in digital computer are must be
represented in digital form – those made of bytes. Hence, sound which comes as an analog
data must converted to a digital data, a process called analog to digital conversion. After
conversion, sound is then represented in a bits pattern made of 0s and 1s. The following
figure show how the intensity of the sound signal can be represented to digital form
To convert an analog wave into digital, converters use a process called sampling. They
sample the height of the sound wave at regular intervals of time, often small fractions of a
second. If one byte is used to hold a single sample of an analog wave, then the wave can be
one of 256 different heights (0 being the lowest height and 255 being the highest). These
heights represent the decibel level of the sound. Thus a spoken word might occupy several
hundred bytes - each being a sample of the sound wave of the voice at a small fraction of a
second. If these 100 bytes were sent to a computer's speaker, the spoken word would be
reproduced.
14