You are on page 1of 55

3/14/2016

Ch1: Digital Systems and Binary Numbers


1

What is a computer?

• Computer is an electronic device, which accepts data,


processes it and outputs the results in the form of reports.
Original objective of computer was to make fast calculations,
but the modern computers besides performing fast
calculations can store large volume of data, process and
retrieve data as and when desired. Hence computers are
also known as data processors.
• Computer is a system. A system is a group of integrated parts to
achieve a common objective. Computer is made up of integrated
parts (input, control, ALU, storage and output unit) . All the parts
work together to process data.

1
3/14/2016

Anatomy of a Digital Computer

• The computer consist of a set of physical components that


constitute a computer system. Some of the major components
of a digital computer are:
– Motherboard (MB).
– Input Unit/Output Unit.
– Central Processing Unit (CPU).
– Primary Memory.
– Hard Disk (HD).

Motherboard (MB)

• The motherboard is
the main component
inside the case. It
serves to connect all
of the parts of a
computer together.
• The MB uses Buses to
transfer the data
between the
computer parts.

2
3/14/2016

Bus
• Bus: A bus, in computing, is a set of physical connections (cables,
circuits, etc.) which can be shared by multiple hardware
components in order to communicate with one another.
• A bus is simply a circuit that connects one part of the motherboard
to another.
• A bus is characterized by the amount of information that can be
transmitted at once. This amount, expressed in bits.

Input Unit
• Input units contain devices with the help of which we enter
data into computer. This unit is linked between user and
computer. Input devices translate the human-being information
into the form understandable by a computer.
• Examples of input devices:
• (1) Keyboard (2) Mouse (3) light pen (4) Scanner (5) Joystick (6)
Voice recognizer (7) Card reader (8) OCR (Optical Character
Reader) …etc.

3
3/14/2016

Central Processing Unit (CPU)


• The Central Processing Unit (CPU) is responsible for interpreting
and executing most of the commands from the computer's
hardware and software.
• The major components of the CPU are:
– Arithmetic and logic unit (ALU).
– Control Unit (CU).
– Registers.

ALU

• Arithmetic and logic unit (ALU): The ALU does the actual
computation or processing of data.

4
3/14/2016

CU

• Control Unit (CU): The CU controls the movement of data and


instruction into and out of the CPU and controls the operation of
the ALU.

Registers

• Registers: the registers are storage locations, treated as a


memory, that used by the CPU to store instructions and data
temporarily while an instruction is being executed.

10

5
3/14/2016

Primary Memory
• The primary memory (often referred to simply as memory) refers to
the electronic storage place for data and instruction where CPU can
access quickly. This unit supplies information to the other units of
the computer when needed.
• Primary memory is called RAM (Random Access Memory) because
you can randomly access any location directly in a memory.
• The CPU access the RAM in direct fashion, that is, the CPU can
access any location of this memory either to read information from
it or store information in it.
• RAM is the place in a computer where the operating system,
application programs, and data in current use are kept so that they
can be quickly reached by the computer's processor.

Dr. Mosleh Abualhaj 11

Cont.
• RAM volatile in nature, as soon as powered turned off, the
information stored in it will lost.
• There is another kind of memory called cache memory. The cache
logically positioned between the registers, and primary memory.

Dr. Mosleh Abualhaj 12

6
3/14/2016

Hard Disk (HD)


• The HD drive is the main, and usually largest, data storage device
in a computer. The operating system, software and most other files
are stored in the HD drive. HD is non-volatile. Hierarchy of Memories

13

Data Flow

Dr. Mosleh Abualhaj 14

7
3/14/2016

Cont.
• In the diagram, the arrows indicate the direction of data flow.
Some data flows in one direction only. In some cases it flows in
both directions.
• At the heart of the computer is the microprocessor, This contains
several REGISTERS to store data and an ARITHMETIC LOGIC UNIT
(ALU) which manipulates data. It acts as the central processing unit
(CPU) of the computer, carrying out a sequence of instructions,
called a program.
• The program may be stored in memory, as software, or written into
the memory from tape or disk.
• The computer needs to communicate with the outside world via
interfaces which are usually a plug or socket of some type.

15

Unit of Memory
• The various units used to measure computer memory, are as
follows:
– Bit: Bit, Abbreviation for binary digit, is basic unit of memory. It is
– smallest unit of information. Bit is represented by a lower case b.
– Byte: A unit of 8 bits is known as a byte. Hence, a byte is able to contain
– any binary number between 00000000 and 11111111. It is represented by
– uppercase B.
– Kilobyte: One KB is equal to 1024 bytes.
– Megabyte: One MB is equal to 1024 KB.
– Gigabyte: One GB is equal to 1024 MB.
– Terabyte: One TB is equal to 1024 GB.

Dr. Mosleh Abualhaj 16

8
3/14/2016

Numbering Systems
17

Numbering Systems
Decimal Binary Octal Hexadecimal
Base 10 Base 2 Base 8 Base 16
0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
16 10000 20 10
17 10001 21 11
18 10010 22 12

18

9
3/14/2016

Decimal Number System


• A decimal number, i.e. 7392 is made of decimal digits (0, 1, … 9),
the value of each digit depends on its position.
• Base (also called radix) = 10
– 10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
• Digit Position
– Integer & fraction
2 1 0 -1 -2

5 1 2 7 4

Cont.
• Digit Weight
– Weight = (Base) Position
100 10 1 0.1 0.01

• Magnitude
– Sum of “Digit x Weight”
500 10 2 0.7 0.04

• Formal Notation
d2*B2+d1*B1+d0*B0+d-1*B -1+d-2*B -2
(512.74)10
• Ex: 7392 = 7*10^3 + 3*10^2 + 9*10^1 + 2*10^0

10
3/14/2016

Binary Number

• A digital device works on two levels of signal, High and Low. The
High-level signal basically corresponds to some high-level signal
(say 5 Volt or 12 Volt) and Low-level signal basically corresponds
to Low-level signal (say 0 Volt).
• Since Computer is a digital electronic device, we have to deal
with two kinds of electrical signals. But while designing a new
computer system or understanding the working principle of
computer, it is always difficult to write or work with 0V or 5V.
• These two signals corresponds to two levels of electrical signals,
and symbolically we represent them as 0 and 1.
• Therefore, the Binary Number System come into picture, which
deals only with two numbers 0 and 1.

Dr. Mosleh Abualhaj 21

Cont.
• An Binary number, i.e. 110 is made of Binary digits (0, 1), the value
of each digit depends on its position.
• Base (also called radix) = 2
– 2 digits {0, 1}
• Digit Position
– Integer & fraction
2 1 0 -1 -2

1 0 1 0 1

11
3/14/2016

Cont.
• Digit Weight
Position
– Weight = (Base)
4 2 1 1/2 1/4

• Magnitude
– Sum of “Digit x Weight”
4 0 1 0/2 1/4

• Formal Notation
d2*B2+d1*B1+d0*B0+d-1*B -1+d-2*B -2
(101.01)2 =(5.25)10
• Ex: 110= 1*2^2 + 1*2^1 + 0*2^0= (6)10

Binary from Zero to Fifteen


Decimal Binary
Number Number

Notice the pattern of zeros and ones in 0 0000


each column. 1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111

12
3/14/2016

Special Powers of 2
210 (1024) is Kilo, denoted "K“
220 (1,048,576) is Mega, denoted "M“
230 (1,073, 741,824)is Giga, denoted "G"
240 (1,099,511,627,776 ) is Tera, denoted “T"

Octal Number System


• An octal number, i.e. 372 is made of octal digits (0, 1, … 7), the
value of each digit depends on its position.
• Base (also called radix) = 8
– 8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }
• Digit Position
– Integer & fraction
2 1 0 -1 -2

5 1 2 7 4

13
3/14/2016

Cont.
• Digit Weight
Position
– Weight = (Base)
64 8 1 1/8 1/64

• Magnitude
– Sum of “Digit x Weight”
320 8 2 7/8 4/64
• Formal Notation
d2*B2+d1*B1+d0*B0+d-1*B -1+d-2*B -2

(512.74)8 =(330.9375)10

• Ex: 372 = 3*8^2 + 7*8^1 + 2*8^0= (250)10

Hexadecimal Number System


• An Hexadecimal number, i.e. A7C is made of Hexadecimal digits (0,
1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F), the value of each digit
depends on its position.
• Base (also called radix) = 16
– 16 digits {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}
• Digit Position
– Integer & fraction
2 1 0 -1 -2

1 E 5 7 A

14
3/14/2016

Cont.
• Digit Weight
Position
– Weight = (Base)
256 16 1 1/16 1/256

• Magnitude
– Sum of “Digit x Weight”
256 224 5 7/16 A/256

• Formal Notation
d2*B2+d1*B1+d0*B0+d-1*B -1+d-2*B -2
(1E5.7A)16 =(485.4765625)10

• Ex: A7C = 10*16^2 + 7*16^1 + 12*16^0= (2684)10

Homework
• List the octal and hexadecimal numbers from 16 to 32.
• What is the exact number of bytes in a system that contains (a) 32K
bytes, (b) 64M bytes, and (c) 6.4G bytes?
• Convert the following numbers with the indicated bases to
decimal: (435)8
• What is the largest binary number that can be expressed with 16
bits? What are the equivalent decimal and hexadecimal numbers?

30

15
3/14/2016

Numbering System Conversion


Dr. Mosleh Abualhaj 31

Decimal (Integer) to Binary: Method1

• Divide the number by the ‘Base’ (=2)


• Take the remainder (either 0 or 1) as a coefficient
• Take the quotient and repeat the division

32

16
3/14/2016

Example1

• Convert decimal 13 to binary.

Quotient Remainder Coefficient


/2= 6 1 a0 = 1
/2= 3 0 a1 = 0
/2= 1 1 a2 = 1
/2= 0 1 a3 = 1
Answer: (13)10 = (a3 a2 a1 a0)2 = (1101)2

MSB LSB

33

Example2

• Convert decimal 41 to binary.

• Note: Conversion from decimal integers to any base‐r system


is similar to this example, except that division is done by r
instead of 2.
Dr. Mosleh Abualhaj 34

17
3/14/2016

Example Decimal to Octal


• Convert decimal 153 to octal. The required base r is 8. First, 153 is
divided by 8 to give an integer quotient of 19 and a remainder of
1. Then 19 is divided by 8 to give an integer quotient of 2 and a
remainder of 3. Finally, 2 is divided by 8 to give a quotient of 0 and
a remainder of 2. This process can be conveniently manipulated as
follows:

Dr. Mosleh Abualhaj 35

Decimal (Integer) to Binary:


Method2
1. Create a table whose leftmost column is the greatest power of 2
less than the number you want to convert. If the number is
between 64 and 127, the leftmost column will be 64. If the
number is between 128 and 255, the leftmost column will be
128. Each column in the table is a power of 2. The rightmost
column is 20 (= 1), the next one to the left is 21 (= 2), the next is
22 (= 4), etc. Instead of thinking about powers of 2, you can just
think bout doubling each number to get the value for the next
column to the left. This will typically look like:

36

18
3/14/2016

Cont.

2. Start by comparing the number you want to convert to the


value leftmost column. If you’ve setup the table correctly, it
should be less than the column value, so put a 1 in the column.
3. Add up the values of all the columns you’ve put 1’s in so far.
This is your running total. Take the running total and add the
value of the next column. If the result is less than the number
you want to convert, put a 1 in this column. If the result is
greater than the number you want to convert, put a 0 in this
column.
4. Repeat the previous step until all columns are filled.

37

Example1

• Convert the decimal number 87 to binary.

38

19
3/14/2016

Example2

• Convert the decimal number 105 to binary.

39

Decimal (Fraction) to Binary


Conversion
• Multiply the number by the ‘Base’ (=2)
• Take the integer (either 0 or 1) as a coefficient
• Take the resultant fraction and repeat the multiplication

40

20
3/14/2016

Example1

• Convert the number 0.625 to binary.

Integer Fraction Coefficient


0.625 * 2 = 1 . 25 a-1 = 1
0.25 * 2 = 0 . 5 a-2 = 0
0.5 *2= 1 . 0 a-3 = 1
Answer: (0.625)10 = (0.a-1 a-2 a-3)2 = (0.101)2

MSB LSB

41

Example2

• Convert the number 0.6875 to binary.

• Note: To convert a decimal fraction to a number expressed in


base r, a similar procedure is used. However, multiplication is by
r instead of 2, and the coefficients found from the integers may
range in value from 0 to r - 1 instead of 0 and 1.
42

21
3/14/2016

Example Decimal to Octal


• Convert (0.513)10 to octal.

• Note: The conversion of decimal numbers with both integer and


fraction parts is done by converting the integer and the fraction
separately and then combining the two answers.

43

Additional Issue - Fractional Part

• Note that in this conversion, the fractional part can become 0 as


a result of the repeated multiplications.
• In general, it may take many bits to get this to happen or it may
never happen.
• Example Problem: Convert 0.6510 to N2
– 0.65 = 0.1010011001001 …
– The fractional part begins repeating every 4 steps yielding
repeating 1001 forever!
• Solution: Specify number of bits to right of radix point and round
or truncate to this number.

44

22
3/14/2016

Binary to Decimal Conversion


1. Create a table with enough columns for your binary number.
(See instructions in decimal to binary section.)
2. Fill in the binary number in the table making sure that the
rightmost digit is aligned under 1.
3. For each column containing a 1, take the value of that column
(e.g., 64, 32, etc.) and add it to the total.

Cont.
• Ex1: Convert the Binary number 1010111 to decimal

• Ex2: Convert the Binary number 1101001 to decimal

23
3/14/2016

Octal from/to Binary Conversion


• Since 23 = 8, each octal digit converts to 3 binary digits
Octal: 0 1 2 3 4 5 6 7
Binary: 000 001 010 011 100 101 110 111

• Ex1: Determine binary equivalent of (231)8


Octal = 2 3 1
Binary= 010 011 001
Thus the binary equivalent of (231)8 is 010011001

• Ex2: Determine binary equivalent of (345)8


Octal = 3 4 5
Binary= 011 100 101
Thus the binary equivalent of (231)8 is 011100101

Cont.
• Conversion from binary to octal is done by reversing the
preceding procedure.
• Ex3:

24
3/14/2016

Hexadecimal from/to Binary Conversion

• Since 24 =16, each Hexadecimal digit converts to 4 binary digits


Hexadecimal: 0 1 2 3 4 5 6 7
Binary: 0000 0001 0010 0011 0100 0101 0110 0111
Hexadecimal: 8 9 A B C D E F
Binary: 1000 1001 1010 1011 1100 1101 1110 1111

• Ex1: Determine binary equivalent of (765)16


Hexadecimal = 7 6 5
Binary = 0111 0110 0101
Thus the binary equivalent of (765)16 is 0111 0110 0101
• Ex2: Determine binary equivalent of (A2DE)16
Hexadecimal = A 2 D E
Binary = 1010 0010 1101 1110
Thus the binary equivalent of (A2DE)16 is 1010001011011110

Cont.
• Conversion from binary to hexadecimal is done by reversing
the preceding procedure.
• Ex3:

25
3/14/2016

Why Hexadecimal?
• During communication between people (about binary
numbers in the computer), the octal or hexadecimal
representation is more desirable because it can be expressed
more compactly with a third or a quarter of the number of
digits required for the equivalent binary number. Thus, most
computer manuals use either octal or hexadecimal numbers
to specify binary quantities. The choice between them is
arbitrary, although hexadecimal tends to win out, since it can
represent a byte with two digits.

Homework
• Convert the hexadecimal number 64CD to binary, and then
convert it from binary to octal.
• Convert the decimal number 431 to binary.
• Convert the binary number 0110110011 to decimal, binary, and
hexadecimal.

26
3/14/2016

Homework
• Convert the decimal number 431 to binary in two ways: (a) convert
directly to binary; (b) convert first to hexadecimal and then from
hexadecimal to binary. Which method is faster?
• Express the following numbers in decimal: (10110.0101)2, (16.5)16,
(26.24)8, DADA.B)16, (1010.1101)2.
• Convert the following binary numbers to hexadecimal and to
decimal: (a) 1.10010, (b) 110.010. Explain why the decimal answer
in (b) is 4 times that in (a).

53

Complement of Numbers
54

27
3/14/2016

Complements
• Complements are used in digital computers to simplify the
subtraction operation and for logical manipulation. Simplifying
operations leads to simpler, less expensive circuits to implement
the operations.
• There are two types of Complements in binary:
– One’s complement.
– Two’s complement.
• There are two types of Complements in decimal:
– 10’s complement
– 9’s complement

One’s Complement
• The 1’s complement of a binary number is formed by changing
1’s to 0’s and 0’s to 1’s.
• Ex1: The 1’s complement of 1011000 is 0100111.
• Ex2: The 1’s complement of 0101101 is 1010010.

28
3/14/2016

Two’s Complement
• The 2’s complement of a binary number is formed by adding 1 to
its 1’s complement or by leaving all least significant 0’s and the
first 1 unchanged and replacing 1’s with 0’s and 0’s with 1’s in all
other higher significant digits.
• Ex1: The 2’s complement of 1011000 is 0100111+1= 0101000.
• Ex2: The 2’s complement of 0101101 is 1010010+1= 1010011.
• Ex3: The 2's complement of 1101100 is 0010100.
• Ex4: The 2's complement of 0110111 is 1001001.

9’s Complement
• The 9’s complement of a decimal number is obtained by
subtracting each digit from 9.
• Ex1: The 9’s complement of 546700 is 999999 - 546700 = 453299.
• Ex2: The 9’s complement of 012398 is 999999 - 012398 = 987601.

29
3/14/2016

10’s complement
• The 10’s complement of a decimal is obtained by adding 1 to the
9’s complement value or by leaving all least significant 0’s
unchanged, subtracting the first nonzero least significant digit
from 10, and subtracting all higher significant digits from 9.
• Ex1: The 10’s complement of 2389 is 7610 + 1 = 7611.
• Ex2: The 10’s complement of 012398 is 987602.
• Ex3: The 10’s complement of 246700 is 753300.

Complements Cont…
• In the previous definitions, it was assumed that the numbers did
not have a radix point. If the original number N contains a radix
point, the point should be removed temporarily in order to form
the r’s or (r - 1)’s complement. The radix point is then restored to
the complemented number in the same relative position.
• It is also worth mentioning that the complement of the
complement restores the number to its original value.
• The (r - 1)’s complement of octal or hexadecimal numbers is
obtained by subtracting each digit from 7 or F (decimal 15),
respectively.

30
3/14/2016

Homework
• Obtain the 1’s and 2’s complements of the following binary
numbers:
– (a) 00010000 (b) 00000000 (c) 11011010 (d) 10101010 (e) 10000101 (f)
11111111.
• Find the 9’s and the 10’s complement of the following decimal
numbers:
– (a) 25,478,036 (b) 63, 325, 600 (c) 25,000,000 (d) 00,000,000.
• (a) Find the 16’s complement of C3DF. (b) Convert C3DF to binary.
(c) Find the 2’s complement of the result in (b). (d) Convert the
answer in (c) to hexadecimal and compare with the answer in (a).

61

Signed Binary Numbers


62

31
3/14/2016

Signed Numbers Representation


• There are three different ways to represent a Signed Binary
Numbers:
– Signed‐magnitude: In this notation, the number consists of a magnitude
and a bit (0 or 1) indicating the sign. The leftmost bit represents the sign
and the rest of the bits represent the number, where 0 indicates positive
number and 1 indicates negative number.
• For example, the string of bits 01001 can be considered as 9 (unsigned binary) or as +9
(signed binary) because the leftmost bit is 0. The string of bits 11001 represents the
binary equivalent of 25 when considered as an unsigned number and the binary
equivalent of -9 when considered as a signed number. This is because the 1 that is in the
leftmost position designates a negative and the other four bits represent binary 9.
Usually, there is no confusion in interpreting the bits if the type of representation for the
number is known in advance.
– Signed‐1’s‐complement: negates a number by taking its 1’s complement.
– Signed‐2’s‐complement: negates a number by taking its 2’s complement.
The 2’s complement is the most common.

Four‐bit Signed Binary


• All possible four‐bit signed binary numbers in the three representations

32
3/14/2016

Binary Arithmetic Operations


65

Binary Addition
• Binary addition performed using the same rules as decimal except
all numbers are limited to combinations of zeros (0) and ones (1).
The binary addition rules are shown in the following Table:

33
3/14/2016

Examples

Ex1:

Ex2:

Cont.

Ex3:

Ex4:

34
3/14/2016

Negative Numbers
• Not all integers are positive.
• What about negative numbers?
• What if we wanted to do: 1410 + ( - 210) = 1210
• Given the nature of the machine itself, how do we represent a
negative number?

Addition of Negative Numbers


• Binary Addition of negative numbers using 2’s Complement:
1. Decide how many bits the computer has available for your operations.
suppose 8bits.
2. Determine the 2’s complement form for the numbers. Positive 2's
complement numbers are represented as the simple binary.
3. Add the numbers using the binary addition rule.
4. If the result overflow then the overflow bit is ignored.

35
3/14/2016

Example
• Ex: Find 1410 + ( - 610) = 810
1. Write the 2’s complement form for the numbers.
• Since 14 is positive then it is 0 0 0 0 1 1 1 0
• Negative numbers in the 2’s complement form need to be
obtained by:

Cont.
2. Add the numbers using the binary addition rule.

36
3/14/2016

Binary Subtraction

• Likewise in the decimal system we subtract decimal digit from


a smaller digit by borrowing from next column, the same rule can
be adopted in binary subtraction also. The rules for binary
subtraction are shown in following Table:

Examples
• Ex1:

• Ex2:

37
3/14/2016

Problem of Negative Numbers


Subtraction
• Ex3:

• When so much borrowing is involved the problem is very error


prone.
• Not only was the example above complex because of all the
borrowing required but computers have additional problems with
signed or negative number presenters. Given the nature of the
machine itself, how do we a negative number?
• Therefore, its better to use the 2’s complement since we can
perform all the operations in addition.

Subtraction with Complements


• Binary Subtraction using 2’s Complement:
1. Decide how many bits the computer has available for your operations.
suppose 8bits.
2. Determine the 2’s complement form for the numbers. Positive 2's
complement numbers are represented as the simple binary.
3. Add the numbers using the binary addition rule.
4. If the result overflow then the overflow bit is ignored.

38
3/14/2016

Example1
• Find 1410 – 610  1410 + ( - 610) = 810
1. Write the 2’s complement form for the numbers.
• Since 14 is positive then it is 0 0 0 0 1 1 1 0.
• Negative numbers in the 2’s complement form need to be obtained by:

Cont.
2. Add the numbers using the binary addition rule.

39
3/14/2016

Example2
• Find 1210 – 910  1210 + ( - 910) = 310
1. Write the 2’s complement for the numbers.
• Since 12 is positive then it is 00001100
• Finding -9 would require the following three steps:

Cont.
2. Add the numbers using the binary addition rule.

40
3/14/2016

Example3
• Find 2510 – 1410  2510 + ( - 1410) = 1110
1. Write the 2’s complement form for the numbers.
• Since 25 is positive then it is 00011001
• Finding -1410 would require the following three steps:

Cont.
2. Add the numbers using the binary addition rule.

41
3/14/2016

Example4
• Find 910 – 1410  910 + ( - 1410) = -510
1. Write the 2’s complement form for the numbers.
• Since 9 is positive then it is 00001001
• Finding -1410 would require the following three steps:

Cont.
2. Add the numbers using the binary addition rule.

• Since the answer starts with a “1” in its sign bit, it is a negative
number. We do the “flipping/adding 1” thing to convert any
positive 2’s complement number to its corresponding negative
number and vice versa):

42
3/14/2016

Example5
• Find -2510 + 1810 = -710
1. Write the 2’s complement form for the numbers.
• Since 18 is positive then it is 00010010
• Finding -2510 would require the following three steps:

Cont.
2. Add the numbers using the binary addition rule.

• Since the answer starts with a “1” in its sign bit, it is a negative
number.

43
3/14/2016

Example6
• Find -310 – (-410) = -310 + (410) = 110
1. Write the 2’s complement form for the numbers.
• The 2’s complement of -3 is 11111101
• The 2’s complement of 4 is 00000100

2. Add the numbers using the binary addition rule.


11111101 (-3)
00000100 (4)
00000001 (1)

Same Hardware Circuit


• It is worth noting that binary numbers in the signed‐complement
system are added and subtracted by the same basic addition and
subtraction rules as unsigned numbers. Therefore, computers
need only one common hardware circuit to handle both types of
arithmetic .

44
3/14/2016

Overflow
• In order to obtain a correct answer, we must ensure that the
result has a sufficient number of bits to accommodate the sum.
If we start with two n‐bit numbers and the sum occupies n + 1
bits, we say that an overflow occurs. When one performs the
addition with paper and pencil, an overflow is not a problem,
because we are not limited by the width of the page. We just
add another 0 to a positive number or another 1 to a negative
number in the most significant position to extend the number to
n + 1 bits and then perform the addition. Overflow is a problem
in computers because the number of bits that hold a number is
finite, and a result that exceeds the finite value by 1 cannot be
accommodated.

Homework
• Perform subtraction on the given unsigned binary numbers using
the 2’s complement of the subtrahend. Where the result should be
negative, find its 2’s complement and affix a minus sign.
– (a) 10011 - 10010, (b) 100010 – 100110 (c) 1001 - 110101 (d) 101000 - 10101
• Convert decimal +49 and +29 to binary, using the
signed‐2’s‐complement representation and enough digits to
accommodate the numbers. Then perform the binary equivalent of
(+29) + (-49), (-29) + (+49), and (-29) + (-49). Convert the answers
back to decimal and verify that they are correct.

90

45
3/14/2016

Binary Codes
91

Binary Codes
• Digital systems represent and manipulate not only binary
numbers, but also many other discrete elements of information.
• Any discrete element of information that is distinct among a group
of quantities can be represented with a binary code.
• An n‐bit binary code is a group of n bits that assumes up to 2n
distinct combinations of 1’s and 0’s, with each combination
representing one element of the set that is being coded.

46
3/14/2016

Binary‐Coded Decimal (BCD)


• A binary code that distinguishes among 10 elements must contain
at least four bits, but 6 out of the 16 possible combinations remain
unassigned.
• Table 1.4 gives the four‐bit code for one decimal digit.

Cont.
• A number with k decimal digits will require 4k bits in BCD.
– Decimal 396 is represented in BCD with 12 bits as 0011 1001 0110, with each
group of 4 bits representing one decimal digit.
• Consider decimal 185 and its corresponding value in BCD and
binary: (185)10 = (0001 1000 0101)BCD = (10111001)2.
– The BCD value has 12 bits to encode the characters of the decimal value, but
the equivalent binary number needs only 8 bits. It is obvious that the
representation of a BCD number needs more bits than its equivalent binary
value.
• It is important to realize that BCD numbers are decimal numbers
and not binary numbers, although they use bits in their
representation. The only difference is that decimals are written
with the symbols 0, 1, 2, …, 9 and BCD numbers use the binary
code 0000, 0001, 0010, …, 1001.

47
3/14/2016

ASCII Character Code


• Many applications of digital computers require the handling not
only of numbers, but also of other characters or symbols, such as
the letters of the alphabet.
• To represent the names and other pertinent information, it is
necessary to formulate a binary code for the letters of the
alphabet, numerals and special characters (such as $).
• An alphanumeric character set is a set of elements that includes
the 10 decimal digits, the 26 letters of the alphabet, and a number
of special characters. Such a set contains between 36 and 64
elements if only capital letters are included, or between 64 and 128
elements if both uppercase and lowercase letters are included. In
the first case, we need a binary code of six bits, and in the second,
we need a binary code of seven bits.

Cont.
• The standard binary code for the alphanumeric characters is the
American Standard Code for Information Interchange (ASCII),
which uses seven bits to code 128 characters, as shown in Table
1.7. The letter A, for example, is represented in ASCII as 1000001
(column 100, row 0001).
• ASCII is a seven‐bit code, but most computers manipulate an
eight‐bit quantity as a single unit called a byte. Therefore, ASCII
characters most often are stored one per byte.
• When we press a A, so actually A means immediately it is
converted to a 7 bit binary numbers. This is predefined this is a
predefined numbers say this 1000001, this is my capital A.

48
3/14/2016

Cont.

Cont.

49
3/14/2016

Error‐Detecting Code
• To detect errors in data communication and processing, an eighth
bit is sometimes added to the ASCII character to indicate its parity.
A parity bit is an extra bit included with a message to make the
total number of 1’s either even or odd. Consider the following two
characters and their even and odd parity:

Homework
• Convert decimal 6,514 to both BCD and ASCII codes. For ASCII, an
even parity bit is to be appended at the left.
• Decode the following ASCII code:
– 1010011 1110100 1100101 1110110 1100101 0100000 1001010 1101111
1100010 1110011.
• List the ASCII code for the 10 decimal digits with an even parity bit
in the leftmost position.

100

50
3/14/2016

Binary Multiplication
• 0×0=0
• 0×1=0
• 1×0=0
• 1×1=1

Binary Multiplication
• 0×0=0
• 0×1=0
• 1×0=0
• 1×1=1

51
3/14/2016

Binary Division

Binary Storage and Registers


104

52
3/14/2016

Registers
• A binary cell is a device that possesses two stable states and is
capable of storing one bit (0 or 1) of information.
• A register is a group of binary cells. A register with n cells can store
any discrete quantity of information that contains n bits. Consider,
for example, a 16‐bit register with the following binary content:
1100001111001001.
• The same bit configuration may be interpreted differently for
different types of data depending on the application.
• For the particular example shown:
– For binary numbers the register contains the equivalent of the decimal
number 50,121.
– For the ASCII code the register contains the two characters C (the leftmost
eight bits) and I (the rightmost eight bits)

Registers Transfer
• In digital systems, a register transfer operation is a basic operation
that consists of a transfer of binary information from one set of
registers into another set of registers.
• The transfer may be direct, from one register to another, or may
pass through data‐processing circuits to perform an operation.
• Figure 1.1 illustrates the transfer of information among registers
and demonstrates pictorially the transfer of binary information
from a keyboard into a register in the memory unit.

53
3/14/2016

Cont.

Binary Information Processing


• Binary variables are manipulated by means of digital logic circuits.
• Figure 1.2 illustrates the process of adding two 10‐bit binary
numbers.
• Memory registers store information and are incapable of
processing the two operands. However, the information stored in
memory can be transferred to processor registers, and the results
obtained in processor registers can be transferred back into a
memory register for storage until needed again.

54
3/14/2016

Cont.

55

You might also like