0% found this document useful (0 votes)
7 views79 pages

Chapter 1

Chapter 1 covers digital systems and binary numbers, including the fundamentals of digital computing, number systems, and conversions between different bases. It discusses the components of computer architecture, the representation of binary values, and the operations of addition, subtraction, multiplication, and division in binary. The chapter also explains the significance of hexadecimal and octal systems in computing, along with methods for converting between these number systems.

Uploaded by

mhsna6484
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views79 pages

Chapter 1

Chapter 1 covers digital systems and binary numbers, including the fundamentals of digital computing, number systems, and conversions between different bases. It discusses the components of computer architecture, the representation of binary values, and the operations of addition, subtraction, multiplication, and division in binary. The chapter also explains the significance of hexadecimal and octal systems in computing, along with methods for converting between these number systems.

Uploaded by

mhsna6484
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 79

Chapter 1

Digital Systems and Binary


Numbers
Outline of Chapter 1

 1.1 Digital Systems


 1.2 Binary Numbers
 1.3 Number-base Conversions
 1.4 Octal and Hexadecimal Numbers
 1.5 Complements
 1.6 Signed Binary Numbers
 1.7 Binary Codes
Digital Systems and Binary Numbers

 Digital age and information age


 Digital computers
 General purposes
 Many scientific, industrial and commercial applications
 Digital systems
 Telephone switching exchanges
 Digital camera
 Electronic calculators, PDA's
 Digital TV
 Discrete information-processing systems
 Manipulate discrete elements of information
 For example, {1, 2, 3, …} and {A, B, C, …}…
The primary components of computer architecture
•Central Processing Unit (CPU): Handles instruction processing and execution.
•Memory: Stores data and instructions temporarily or permanently.
•Input/Output (I/O) systems: Facilitates communication between the computer and
external environments
Analog and Digital Signal
 Analog system
 The physical quantities or signals may vary continuously over a specified
range.
 Digital system
 The physical quantities or signals can assume only discrete values.
 Greater accuracy

X(t) X(t)

t t
Analog signal Digital signal
Binary Digital Signal

 An information variable represented by physical quantity.


 For digital systems, the variable takes on discrete values.
 Two level, or binary values are the most prevalent values.
 Binary values are represented abstractly by:
 Digits 0 and 1
 Words (symbols) False (F) and True (T) V(t)
 Words (symbols) Low (L) and High (H)
 And words On and Off
Logic 1
 Binary values are represented by values
or ranges of values of physical quantities. undefine

Logic 0
t
Binary digital signal
Number Systems

 There are four main systems:


1. Decimal Number System
2. Binary Number System
3. Octal Number System
4. Hexadecimal Number System
Number Systems

1. Base 2 Number System called Binary Number


System

2. Base 8 Number System called Octal Number


System

3. Base 10 Number System called Decimal Number


System

4. Base 16 Number System called Hexadecimal


Number System
Decimal Number System
 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

 Digit Weight 5 1 2 7 4
 Weight = (Base) Position
 Magnitude 100 10 1 0.1 0.01
 Sum of “Digit x Weight”
 Formal Notation
500 10 2 0.7 0.04

d2*B2+d1*B1+d0*B0+d-1*B-1+d-2*B-2

(512.74)10
Octal Number System
 Base = 8
 8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }
 Weights
 Weight = (Base) Position 64 8 1 1/8 1/64

 Magnitude 5 1 2 7 4
 Sum of “Digit x Weight”
2 1 0 -1 -2
 Formal Notation
5 *82+1 *81+2 *80+7 *8--1+4 *8--2
=(330.9375)10

(512.74)8
Binary Number System
 Base = 2
 2 digits { 0, 1 }, called binary digits or “bits”
 Weights
 Weight = (Base) Position 4 2 1 1/2 1/4
 Magnitude 1 0 1 0 1
 Sum of “Bit x Weight”
2 1 0 -1 -2
 Formal Notation
1 *22+0 *21+1 *20+0 *2--1+1 *2--2
 Groups of bits 4 bits = Nibble
=(5.25)10
1011
8 bits = Byte (101.01)2
11000101
Hexadecimal Number System
 Base = 16
 16 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F }
 Weights
 Weight = (Base) Position
256 16 1 1/16 1/256
 Magnitude
 Sum of “Digit x Weight” 1 E 5 7 A
 Formal Notation 2 1 0 -1 -2
1 *162+14 *161+5 *160+7 *16--1+10 *16--2
=(485.4765625)10

(1E5.7A)16
“Hexa” = Greek = Six
Since the western alphabet contains only ten digits, hexadecimal uses
the letters A-F to represent the digits ten through fifteen.
The Power of 2

n 2n n 2n
0 20=1 8 28=256
1 21=2 9 29=512
2 22=4 10 210=1024 Kilo

3 23=8 11 211=2048
4 24=16 12 212=4096
5 25=32 20 220=1M Mega

6 26=64 30 230=1G Giga

7 27=128 40 240=1T Tera


Addition
 Decimal Addition

1 1 Carry
5 5
+ 5 5

1 1 0
Binary Addition

 Column Addition

1 1 1 1 1 1
1 1 1 1 0 1 = 61
+ 1 0 1 1 1 = 23

1 0 1 0 1 0 0 = 84
Binary Subtraction

 Borrow a “Base” when needed

1 2 = (10)2
0 2 2 0 0 2
1 0 0 1 1 0 1 = 77
− 1 0 1 1 1 = 23

0 1 1 0 1 1 0 = 54
Binary Multiplication

 Bit by bit

1 0 1 1 1
x 1 0 1 0
0 0 0 0 0
1 0 1 1 1
0 0 0 0 0
1 0 1 1 1

1 1 1 0 0 1 1 0
Multiplication Example

Multiplicand 1000ten
Multiplier x 1001ten
---------------
1000
0000
0000
1000
----------------
Product 1001000ten

In every step
• multiplicand is shifted
• next bit of multiplier is examined (also a shifting step)
• if this bit is 1, shifted multiplicand is added to the product
Division Example

1001ten Quotient
Divisor 1000ten | 1001010ten Dividend
-1000
10
101
1010
-1000
10ten Remainder

At every step,
• shift divisor right and compare it with current dividend
• if divisor is larger, shift 0 as the next bit of the quotient
• if divisor is smaller, subtract to get new dividend and shift 1
as the next bit of the quotient
Number Base Conversions (10 Conversions)
Magnitude = Sum of “Digit x Weight” Dash line represents Division of decimal by the base

Evaluate
Magnitude
Octal
Division by base
(Base 8)
will be explained
Evaluate will be explained
Magnitude
Decimal Binary
(Base 10) (Base 2)
Division by base will be explained
will be explained

Division by base Hexadecimal


(Base 16)
Evaluate
Magnitude
Decimal (Integer) to Binary Conversion
 Divide the number by the ‘Base’ (=2)
 Take the remainder (either 0 or 1) as a coefficient
 Take the quotient and repeat the division

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

MSB LSB
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 division

Example: (0.625)10
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
Decimal to Octal Conversion
Example: (175)10
Quotient Remainder Coefficient
175 / 8 = 21 7 a0 = 7
21 / 8 = 2 5 a1 = 5
2 /8= 0 2 a2 = 2
Answer: (175)10 = (a2 a1 a0)8 = (257)8

Example: (0.3125)10
Integer Fraction Coefficient
0.3125 * 8 = 2 . 5 a-1 = 2
0.5 *8= 4 . 0 a-2 = 4
Answer: (0.3125)10 = (0.a-1 a-2 a-3)8 = (0.24)8
Decimal to Hexadecimal Conversion

 Steps:
1. Divide the decimal number by 16. Treat the division as an
integer division.
2. Write down the remainder (in hexadecimal).
3. Divide the result again by 16. Treat the division as an integer
division.
4. Repeat step 2 and 3 until result is 0.
5. The hex value is the digit sequence of the remainders from the
last to first.
Example
Hexadecimal and Computing

 It is much easier to work with large numbers


using hexadecimal values than decimal or binary.
One Hexadecimal digit = 4bits

Two hexadecimal digits = 8 bits

Eight bits=1 byte

This makes conversions between hexadecimal


and binary very easy
Counting Hexadecimal

 Starting from zero, we count 00, 01, 02,03,


04, 05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E,
0F,10, 11, 12, 13, 14, 15, 16, 17 18, 19, 1A,
1B, 1C, 1D, 1E, 1F, 20, 21, 22, 23, 24,
25,....
Binary − Octal Conversion
Octal Binary
 8 = 23
 Each group of 3 bits represents an octal 0 000
digit 1 001

2 010
Assume Zeros
Example: 3 011

( 1 0 1 1 0 . 0 1 )2 4 100

5 101

6 110
( 2 6 . 2 )8 7 111

Works both ways (Binary to Octal & Octal to Binary)


Binary − Hexadecimal Conversion
Hex Binary
 16 = 24 0 0000
1 0001
 Each group of 4 bits represents a 2 0010
hexadecimal digit 3 0011
4 0100
5 0101
Assume Zeros 6 0110
Example: 7 0111
8 1000
( 1 0 1 1 0 . 0 1 )2 9 1001
A 1010
B 1011
C 1100
D 1101
(1 6 . 4 )16 E 1110
F 1111

Works both ways (Binary to Hex & Hex to Binary)


Octal − Hexadecimal Conversion
 Convert to Binary as an intermediate step
Example:
( 2 6 . 2 )8

Assume Zeros Assume Zeros

( 0 1 0 1 1 0 . 0 1 0 )2

(1 6 . 4 )16

Works both ways (Octal to Hex & Hex to Octal)


Number Systems

 There are four main systems:


1. Decimal Number System
2. Binary Number System
3. Octal Number System
4. Hexadecimal Number System
Decimal, Binary, Octal and Hexadecimal
Decimal Binary Octal Hex
00 0000 00 0
01 0001 01 1
02 0010 02 2
03 0011 03 3
04 0100 04 4
05 0101 05 5
06 0110 06 6
07 0111 07 7
08 1000 10 8
09 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
Unsigned Numbers
Adding unsigned numbers in binary is quite easy. Recall that
with 4 bit numbers we can represent numbers from 0 to 15.
Addition is done exactly like adding decimal numbers, except
that you have only two digits (0 and 1). The only number facts
to remember are that
0+0 = 0, with no carry,
1+0 = 1, with no carry,
0+1 = 1, with no carry,
1+1 = 0, and you carry a 1.
so to add the numbers 0610=01102 and
0710=01112 (answer=1310=11012) we can write out the
calculation (the results of any carry is shown along the top
row, in italics).
Adding Unsigned Numbers
Signed Binary Numbers

Three ways to represent negative


numbers
Signed magnitude
One’s Complement
Two’s Complement
Signed Numbers
Usually a '0' indicates the number is
positive and a '1' indicates the number
is negative. Using this method we get
the following:
1000011 = -3
0000011 = 3
Unsigned and Signed Numbers
With 8 bits we have for unsigned number:
1. 00000000 - representing 0, the smallest number possible.
2. 11111111 - representing 255, the largest number possible.
3. For a total of 256 possible numbers represented.

Whereas with sign magnitude we have:


1. 11111111 - representing -127, the smallest number possible.
2. 10000000 - representing 0.
3. 00000000 - also representing 0.
4. 01111111 - representing 127, the largest possible number.
5. For a total of 255 possible numbers represented.
2's complement (2C) is the most useful
form of handling negative numbers for
addition and subtraction of signed
numbers.
Negative numbers can be added as is in
a circuit called a “full adder”. 1's
complement numbers are easier/faster to
form, but slow to add: an “end-around
carry” is needed
1's complement and 2's complement of a binary number

The ones' complement of a binary number is defined as the value


obtained by inverting all the bits in the binary representation of the
number (swapping 0s for 1s and vice versa). ... To within a constant
(of −1), the ones' complement behaves like the negative of the
original number with binary addition

Two's complement is a mathematical operation on binary numbers,


and is an example of a radix complement.
It is used in computing as a method of signed number representation.
... In other words, to reverse the sign of most integers (all but one) in
this scheme, you can take the two's complement of its binary
representation
Two's complement
So, to the computer, taking the
negative of a number, that is,
subtracting a number from 0, is the
same as inverting the bits and adding
one, which is Two's complement
Why do we need Two's complement?

Two's complement allows negative and positive


numbers to be added together without any special
logic. ...

This means that subtraction and addition of both


positive and negative numbers can all be done by
the same circuit in the CPU
The primary advantage of two's complement over one's
complement

• Two's complement has only one value for zero.

• One's complement has a "positive" zero and a "negative"


zero.

• Two's complement has only one value for zero, and


doesn't require carry values.

•To add numbers using one's complement you have to first


do binary addition, then add in an end-around carry
value.
1's and 2's complements
By using 1's and 2's complements we
can do all operations, subtraction,
division, and multiplication using
addition method.
This makes circuit design simple and
with only one circuit you get to do
different things.
1's and 2's complements

1’s complement of a binary number is


another binary number obtained by
toggling all bits in it, i.e., transforming
the 0 bit to 1 and the 1 bit to 0.
2’s complement of a binary number is
1 added to the 1’s complement of the
binary number.
Examples
Examples:
 Let numbers be stored using 4 bits 1's
complement of 7 (0111) is 8 (1000)
 1's complement of 12 (1100) is 3 (0011)

Examples:
 Let numbers be stored using 4 bits
 2's complement of 7 (0111) is 9 (1001)
 2's complement of 12 (1100) is 4 (0100)
1's and 2's complements
 These representations are used for signed numbers.
 The main difference between 1′ s complement and 2′ s
complement is that 1′ s complement has two
representations of 0 (zero) – 00000000, which is positive
zero (+0) and 11111111, which is negative zero (-0);
whereas in 2′ s complement, there is only one
representation for zero – 00000000 (+0) because if we
add 1 to 11111111 (-1), we get 00000000 (+0) which is
the same as positive zero. This is the reason why 2′ s
complement is generally used.
Advantage
Another difference is that while adding
numbers using 1′ s complement, we
first do binary addition, then add in an
end-around carry value. But, 2′ s
complement has only one value for
zero, and doesn’t require carry values.
Examples
 Convert to one’s complement:
1. 1010
2. 11110000
3. 10111100 11000000
4. 10100001
 Answers
 One’s complement:
1. 0101
2. 00001111
3. 01000011 00111111
4. 01011110
Examples
 Convert to two’s complement:
1. 1010
2. 11110000
3. 10000000
4. 011111111
 Two’s complement:
1. 0110 (1010 –> 0101 + 1 = 0110)
2. 00010000
3. 10000000 (Result is the same as the original value.)
4. 10000001
Two’s complement
A positive number written in two's-complement notation is the same
as the number written in unsigned notation (although the most
significant bit must be zero). A negative number can be written in
two's complement notation by inverting all of the bits of its absolute
value, then adding one to the result.

A positive integer in two's complement always has a 0 in the


leftmost bit (sign bit) and is represented the same way as an
unsigned binary integer.

+1410 = 01110two's comp

-1410 = 10001 + 1 = 10010two's comp


Convert the following 4-bit 2's comp values to decimal:

0111 = +(1 + 2 + 4) = +7

1000 = -(0111 + 1) = -(1000) = -8

0110 = +(2 + 4) = +6

1001 = -(0110 + 1) = -0111 = -(1 + 2 + 4) = -7

1110 = -(0001 + 1) = -0010 = -2


Addition and Subtraction
Addition works exactly like unsigned addition. This means a
computer that uses 2's complement to store signed integers can use
the same adder circuit to do both signed and unsigned addition.

Subtraction is done by negating and adding.

Binary Unsigned 2's comp

01
0101 5 +5
+ 1001 + 9 + -7
1110 14 -2
Subtraction Using 1’s complement
1. Write down 1’s complement of the
subtrahend.
2. Add this with the minuend.
3. If the result of addition has a carry over then it
is dropped and an 1 is added to the result
4. If there is no carry over, then 1’s complement of
the result of addition is obtained to get the final
result and it is negative.
Example 1:
Evaluate: 110101 – 100101 using 1’s complement
( In decimal 53 - 37 = 16)

Solution:
1’s complement of 100101 is 011010. Hence
minuend - 110101

1’s complement of subtrahend - 011010

Drop Carry over - 1 001111

add 1 to result 1

010000

 The required difference is 10000 (16)


Example 2:
Evaluate 101011 – 111001 (43- 57) = -14
Solution:
1’s complement of 111001 is 000110. Hence
Minuend - 101011

1’s complement - 000110

No carry over 110001

 Take 1’s complement of 110001


 Hence the difference is – 0 0 1 1 1 0 -(14)
Subtraction using 2’s complement

1. Take 2’s complement of the subtrahend is


found.
2. Then it is added to the minuend.
3. If the final carry over of the sum is 1, it is
dropped and the result is positive.
4. If there is no carry over, the two’s
complement of the sum will be the result
and it is negative.
Unsigned 2’s Complement Subtraction Example 1
 Find 010101002 – 010000112

01010100 1 01010100
– 01000011 2’s comp + 10111101
00010001
 The carry of 1 indicates that no correction of
the result is required.
Unsigned 2’s Complement Subtraction Example 2

 Find 010000112 – 010101002


0
01000011 01000011
– 01010100 2’s comp + 10101100
11101111 2’s comp
00010001
 The carry of 0 indicates that a correction of
the result is required.
 Result = – (00010001)
Example 1:
Evaluate: 110110 – 10110 in decimal ( 54 – 22) = 32
Solution:
The numbers of bits in the subtrahend is 5 while that of minuend is 6.
We make the number of bits in the subtrahend equal to that of
minuend by taking a `0’ in the sixth place of the subtrahend.
Now, 2’s complement of 010110 is (101001 + 1) i.e.101010. Adding
this with the minuend.

110110 Minuend

101010 2’s complement of subtrahend


--------------
Carry over 1 100000 Result of addition

After dropping the carry over we get the result of subtraction to be


100000
Example 2:
Evaluate: 10110 – 11010 in decimal ( 22 – 26) = - 4
Solution:

2’s complement of 11010 is (00101 + 1) i.e. 00110. Hence

Minuend 10110

2’s complement of subtrahend 00110


------------
Result of addition 11100

As there is no carry over, the result of subtraction is negative and is


obtained by writing the 2’s complement of 11100 i.e.(00011 + 1) or
00100.
Hence the difference is – 100
Sign Bit
• What did do you notice about the
+127 01111111
most significant bit of the binary pos(+)
+126 01111110
numbers?
+125 01111101
• The MSB is (0) for all positive
numbers. +1 00000001
• The MSB is (1) for all negative 0 00000000
numbers. -1 11111111

• The MSB is called the sign bit. -2 11111110

• In a signed number system, this


-127 10000001
allows you to instantly determine neg(-)
-128 10000000
whether a number is positive or
negative.
2’S Complement Process
The steps in the 2’s Complement process are similar
to the 10’s Complement process. However, you will
now use the base two.
First, complement all of the digits in a number.
– A digit’s complement is the number you add to the digit to
make it equal to the largest digit in the base (i.e., 1 for
binary). In binary language, the complement of 0 is 1, and
the complement of 1 is 0.
Second, add 1.
– Without this step, our number system would have two
zeroes (+0 & -0), which no number system has.
2’s Complement Examples
Example #1
5 = 00000101
Complement Digits

11111010
+1
Add 1
-5 = 11111011

Example #2
-13 = 11110011
Complement Digits

00001100
+1
Add 1
13 = 00001101
Using The 2’s Compliment Process
Use the 2’s complement process to add together
the following numbers.

POS 9 NEG (-9)


+ POS  + 5 + POS  + 5
POS 14 NEG -4

POS 9 NEG (-9)


+ NEG  + (-5) + NEG  + (-5)
POS 4 NEG - 14
POS + POS → POS Answer
If no 2’s complement is needed, use regular binary
addition.

9  00001001
+ 5  + 00000101
14  00001110
POS + NEG → POS Answer
Take the 2’s complement of the negative number and use
regular binary addition.

9  00001001
+ (-5) + 11111011
4  1]00000100
8th Bit = 0: Answer is Positive
Disregard 9th Bit

00000101
 2’s
11111010 Complement
Process
+1
11111011
POS + NEG → NEG Answer
Take the 2’s complement of the negative number and use
regular binary addition.

(-9) 11110111
+ 5  + 00000101
-4  11111100
8th Bit = 1: Answer is Negative

11111100 00001001
To Check:   2’s
Perform 2’s
Complement
00000011 11110110 Complement
Process
On Answer +1 +1
00000100 11110111
NEG + NEG → NEG Answer
Take the 2’s complement of both negative numbers and
use regular binary addition.
2’s Complement
(-9)  11110111 Numbers, See
Conversion Process

+ (-5)  + 11111011 In Previous Slides

-14  1]11110010
8th Bit = 1: Answer is Negative
Disregard 9th Bit

11110010
To Check: 
Perform 2’s
Complement
00001101
On Answer +1
00001110
Signed Binary Numbers
 Arithmetic addition
 The addition of two numbers in the signed-magnitude system follows the rules of
ordinary arithmetic. If the signs are the same, we add the two magnitudes and give
the sum the common sign. If the signs are different, we subtract the smaller
magnitude from the larger and give the difference the sign if the larger magnitude.
 The addition of two signed binary numbers with negative numbers represented in
signed-2's-complement form is obtained from the addition of the two numbers,
including their sign bits.
 A carry out of the sign-bit position is discarded.
 Example:
Signed Binary Numbers

 Arithmetic Subtraction
 In 2’s-complement form:
1. Take the 2’s complement of the subtrahend (including the sign bit) and
add it to the minuend (including sign bit).
2. A carry out of sign-bit position is discarded.

 Example:

( 6)  ( 13) (11111010  11110011)


(11111010 + 00001101)
00000111 (+ 7)
Signed Binary Numbers
Binary Coded Decimal
 BCD Code
 A number with k decimal digits will
require 4k bits in BCD.
 Decimal 396 is represented in BCD
with 12bits as 0011 1001 0110, with
each group of 4 bits representing one
decimal digit.
 A decimal number in BCD is the
same as its equivalent binary number
only when the number is between 0
and 9.
 The binary combinations 1010
through 1111 are not used and have
no meaning in BCD.
Example: BCD codes used in the following decoder:
BCD to 7-Segment Decoder
Binary Coded Decimal
 Example:
 Consider decimal 185 and its corresponding value in BCD and binary:

 BCD addition
 We add 6 (0110) to the digit sum if it exceeds 9.
Binary Coded Decimal
Example:
Consider the addition of 184 + 576 = 760 in BCD:
Binary Codes (ASCII)
 American Standard Code for Information Interchange (ASCII) Character Code
 It uses 7-bit code, 128 possible characters are defined.
 It uses 7-bits

Binary ASCII Codes
 ASCII Character Code It uses 7-bits

You might also like