Arab International
University (AIU)
Faculty of Informatics and
Communications
CS - Chapter 2
Data Representation
2022-2023 / S1
Data Representation
2 ▪ Actually, all data which include numbers, text,
photos, videos, and audio files are represented using
simple switches (ON / OFF).
▪ Computers are electronic devices. If the switch
circuit is closed the current will flow, and vice versa.
▪ Computers use the binary code system.
▪ A binary digit is called a bit, and it may have one of
two values: zero or one.
▪ The word "bit" is an acronym of the phrase
"binary digit".
3
Binary System
4
• People use decimals (0-9), whereas computer uses binary
system which has only two values / digits: 0 and 1
• They can also be called LOW and HIGH, where LOW = 0 and
HIGH = 1
• The binary numbering system has a base of 2 with each position
weighted by a factor of 2:
Converting from Decimal to Binary
5
6 Converting from Binary to Decimal
(10011011)2=(1*27+0*26+0*25+1*24+1*23+0*22+1*21+1*20)10
=(128+0+0+16+8+0+2+1)10 =(155)10
or as following:
7 Binary System Decimal System
0 0
1 1
10 2
11 3
100 4
101 5
110 6
111 7
1000 8
1001 9
1010 10
Binary Numbers
8 2 bits 3 bits 4 bits 5 bits 8 bits word (byte)
0 00 000 0000 00000 00000000
1 01 001 0001 00001 00000001
2 10 010 0010 00010 00000010
3 11 011 0011
4 100 0100
5 101 0101
6 110 0110
7 111 0111
8 1000
9 1001
10 1010 01010 00001010
2 bits word represents 4 different codes 22=4
3 bits word gives 23=8 codes
4 bits word gives 24=16 codes
8 bits word (byte) gives 28=256 codes, n bits word, 2n codes
9 Simple Binary Counting Application
10 Binary Addition
The four basic rules for
adding binary digits are:
Example -1- Perform the following binary additions :
1101 + 1010 , 10111 + 01101
11 Binary Subtraction
The four basic rules for
subtracting binary digits are:
Example -1: Perform the following binary subtraction :
1101 – 0100 , 1001 - 0111
12 Binary Multiplication
The four basic rules for
multiplying binary digits are:
Complements of Binary Numbers
13
1’s complements
2’s complements
They are important because they permit the
representation of negative numbers in computers.
1st Complement
14
Method : Invert each bit to get the 1st complement
Example -1
Example -2 : Determine the first complement of the following binary
00011010 - 11110111 - 10001101
2nd Complement
15
2nd complement = 1st complement + 1
Example:
Application
Example
1- Sign - Magnitude Form:
16
+25 = 00011001
-25 = 10011001
➢ 0 sign bit indicates a positive magnitude
➢ 1 sign bit indicates a negative magnitude
2- 1st Complement Form:
A negative number is the 1st complement of the +25 = 00011001
corresponding positive number -25 = 11100110
3- 2nd Complement Form:
A negative number is the 2nd complement of +25 = 00011001
the corresponding positive number -25 = 11100111
17
Negative Numbers are saved as 2nd complement in computer
• Range of signed integer numbers
2’s complement form:
– (2n – 1) to + (2n – 1 – 1)
• For n=8 bits: -128 to 127
• For n=16 bits: -32768 to 32767
18
Arithmetic Operations with Signed Numbers
❑Addition
❑Subtraction
❑Multiplication
❑Division
1- Addition
19 Four conditions for adding numbers:
• Both numbers are positive.
– Addend
• A positive number that is larger than a negative number.
– Augend
• A negative number that is larger than a positive number.
– Sum • Both numbers are negative.
Add the two numbers and discard any final carry bit as
long as 2nd complement is used for negative numbers.
+
Examples:
Add the two numbers and discard any final carry bit
20
as long as 2nd complement is used for negative
numbers.
+
2- Subtraction
21 – minuend
– subtrahend
– difference
Subtraction is addition with the sign of the
subtrahend changed.
1. Take the 2nd complement of the subtrahend , then add it to
the minuend.
2. Discard any final carry bit.
Example in Decimal number:
30 – 12 = 18 >>>>> 30 + 88 = 118 (88 is the 2nd complement of 12 )
discard carry = 18 21
22
23 3- Multiplication
1. Determine if the signs of the multiplicand and multiplier are the same or
different . Therefore, determine the sign of the product.
2. Change any negative number to true form (un-complemented).
3. Generate the partial products , shift each successive partial product one
bit to the left.
4. Add each successive partial products to the sum of previous partial
product.
5. If the sign bit that was determined in step -1- is negative , take the 2nd
complement of the product.
24
3- Multiplication
There are two methods for multiplication:
• Direct addition
• Partial products
• Direct addition:
Multiply the signed numbers: 01001101 and 00000100
01001101 1st time
+ 01001101 2nd time
10011010 partial sum
+ 01001101 3rd time
11100111 partial sum
+ 01001101 4th time
100110100 Product
25
Partial Product
4- Division of signed numbers: – dividend
– divisor
26 – quotient
Division is equivalent to subtracting the divisor from the dividend
a number of times equal to the quotient.
• If the signs are the same, the quotient is positive.
• If the signs are different, the quotient is negative.
1. Determine if the signs of the dividend and divisor are the same or
different
2. Subtract the divisor from the dividend using 2nd complement addition
and add 1 to the quotient
3. Subtract the divisor from the partial remainder and add 1 to
quotient.
4. If the result is positive , then repeat.
5. If the result is zero or negative , then the division is complete.
Divide : 01100100 by 00011001
Step 1 : the signs of both numbers are positive, so the quotient will be positive. The quotient is
initially zero. 00000000
27
27
Hexadecimal Numbers
28
The hexadecimal number system has 16 digits.
These are : 0 , 1, 2 , 3, 4 , 5 , 6, 7 , 8 , 9, A , B , C , D , E , F
The hexadecimal system has
the base = 16
Compact way of displaying or
writing binary number.
Widely used in computer and
microprocessor application.
Binary to hexadecimal
29 Method:
• Break the binary number into 4-bit groups starting at
the right-most bit , Then:
• Replace each 4-bit group with the equivalent
hexadecimal symbol.
Hexadecimal to Binary
30
Method :
Replace each hexadecimal symbol with the appropriate four bits.
Hexadecimal to Decimal
31
Method
Convert the hexadecimal to binary then convert from binary to decimal.
Decimal to hexadecimal
32
Method :
Repeated division of a decimal number by 16 .
Octal Numbers
33 Decimal Octal Binary
0 0 0000
The Octal number system has 8 digits.
1 1 0001
These are : 0 , 1, 2 , 3, 4 , 5 , 6, 7 2 2 0010
3 3 0011
The Octal system has the base = 8 4 4 0100
5 5 0101
Binary number can easily be converted to 6 6 0110
octal by grouping 3 bits at a time and 7 7 0111
writing the equivalent octal character for 8 10 1000
each group. 9 11 1001
10 12 1010
Express : 001 011 000 001 1102 11 13 1011
in octal. 12 14 1100
13 15 1101
Group the binary number by 3- 14 16 1110
bits starting from the right. Thus, 15 17 1111
130168
34 Representing Characters
The ASCII (American Standard Code for
Information Interchange) uses One Byte
as the basic unit to represent characters
(numbers, English uppercase and lowercase
letters, punctuation marks, and other
symbols).
The character A, for example, is represented
by (01000001)2=(65)10.
Some examples of the character
35 encoding in ASCII - 1
Some examples of the character
36 encoding in ASCII - 2
Some examples of the character
37 encoding in ASCII - 3
38
Unicode
Most operating systems use the international
standard Unicode, which supports all letters in all
natural languages like Arabic, Chinese, Japanese and
Korean.
This encoding uses 16 bits per character, which is
equal to 2 bytes, and so it is possible to encode:
216 = 65536 values.
39
Representing Images
Images are represented by grid of squares (each square
is called pixel "Picture Element").
Using more pixels make the image resolution better.
Assigning only one bit for each pixel gives black and
40 white images as shown in the following picture.
Assigning one byte for each pixel gives 256 different values.
The following picture uses these values for gray levels.
Three bytes are usually assigned for each pixel in colored
41 images, that gives 256*256*256=16777216 different colors.
Each color is made by mixing 3 values of basic colors (Red,
Green and Blue).
The number of bytes assigned to each pixel is called
the Depth of the image.
42
Representing Voices
The voice takes the form of analog waves when
transmitted.
The process of transforming an analog voice to a
digital signal is called Analog-to-Digital conversion.
To perform this operation, a sampling of the analog
voice signal is done at the beginning.
Samples are taken from the amplitude of the analog
voice signal within equal periods (usually parts of the
second).
43 4 – Bit Voice Sampling
These amplitudes represent the Decibel
44
levels of the relevant voice signal.
Consequently, a signal of speech may
require many hundreds of bytes, each of
which is a sample of the amplitude of the
signal.
When these bytes are sent to the speakers
of the computer, the related voice that has
already been processed will be broadcasted.
The sound quality is affected by the
sampling rate. Increasing this rate makes
the digital sound closer to reality.
45 Wave Sampling and coding
Digital and Analog Quantities
46
Analog Quantities
Figure1-1: Graph of an analog quantity (temperature versus time).
47
Discrete and digital Quantities
Figure 1–2 Sampled-value representation (quantization) of the analog
quantity in Figure 1–1.
Each value represented by a dot can be digitized by representing it as
a digital code that consists of a series of 1s and 0s.
Logic Levels
48
Digital electronics uses circuits
that have two states, which are
represented by two different
voltage levels called HIGH and
LOW. The voltages represent
numbers in the binary system.
49
Digital Waveforms (pulse)
Binary values are also represented by
voltage levels.
50
Nonideal pulse
Actual pulses are not ideal but are described by the rise time,
fall time, amplitude, and other characteristics.
Major parts of a digital pulse:
• Base line
• Amplitude
• Rise time (tr)
• Pulse width (tw)
• Fall time (tf)
Digital and Analog Quantities
51
▪ An analog quantities have continuous values.
▪ Digital quantities have discrete sets of values.
▪ Most natural quantities that can be measured quantitatively
occur in nature in analog form.
▪ Analog systems can generally handle higher power than digital
systems.
▪ Digital data can be processed, stored, and transmitted more
efficiently and reliably than analog data .
▪ Digital data has a great advantage when storage is necessary
but can only assign discrete values to each point.
52 Digital and Analog Quantities
Analog quantities have continuous Digital quantities have discrete
values sets of values
Digital and Analog Quantities
53
Types of electronic devices or instruments:
➢ Analog
➢ Digital
➢ Combination analog and digital
Is mobile device analog or digital or combination of them?
An Analog Electronic System
54
Analog and Digital Systems
55
Many systems use a mix of analog and digital
electronics to take advantage of each technology. A
typical CD player accepts digital data from the CD
drive and converts it to an analog signal for
amplification.
Data Transfer
Serial and Parallel Data
56
Data can be transmitted by either serial transfer or parallel transfer.
Illustration of serial and parallel transfer of binary data. Only the data lines are shown.