0% found this document useful (0 votes)
53 views83 pages

Lec 01 - Digital Systems & Binary Numbers

This document provides an overview of binary numbering systems which are important for digital logic design and computer science. It discusses counting in binary and hexadecimal, converting between number bases such as binary to decimal and hexadecimal to decimal, representing signed numbers in binary, binary arithmetic operations, binary coding, and binary storage media. The objectives are to understand why computers use binary and how to perform basic conversions between binary, decimal, and hexadecimal number systems.

Uploaded by

Esmail Atta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
53 views83 pages

Lec 01 - Digital Systems & Binary Numbers

This document provides an overview of binary numbering systems which are important for digital logic design and computer science. It discusses counting in binary and hexadecimal, converting between number bases such as binary to decimal and hexadecimal to decimal, representing signed numbers in binary, binary arithmetic operations, binary coding, and binary storage media. The objectives are to understand why computers use binary and how to perform basic conversions between binary, decimal, and hexadecimal number systems.

Uploaded by

Esmail Atta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 83

Theory

Binary Numbering Systems


in Course of
DIGITAL LOGIC DESIGN
UNDER THE FACULTY OF
COMPUTER & IT
CS Dep, LEVEL 2

Eng. Bakeel Azman


2023
Agenda
• You have to accomplish :
1. Count in binary
2. Count in hexadecimal
3. Convert binary to decimal, binary to hexadecimal and both
to decimal and vs.
4. Represent sign number in binary
5. Compute arithmetic operations in binary and hexadecimal
as decimal
6. Binary coding
7. Binary Storage media
Objectives
 Understanding why computers use binary (Base-2) number.
 Understanding how to convert Base-2 numbers to Base-10.
 Understand how to convert Base-16 numbers to Base-10 or Base 2.
 Students are able to complete tasks such as wiring and checking the
functionality of computer chips, specifying the output when the
input is zero or one and determining the output of the gate.
To practice,
the student should have been known below:
1. What we mean by number system?
2. What is a binary system?
3. Why we need study the binary system?
4. How to form a number through general expressions?
5. Explain the purpose of conversion between different
number system?
6. When we are required to represent a number into its
complement?
7. Where can the binary value be existed?
Why Binary System?
• Computers are made of a series of switches
• Each switch has two states: ON or OFF
• Each state can be represented by a number – 1
for “ON” and 0 for “OFF”
• Tow states can represent tow physical states:
– Voltage
– Non-voltage
Common Number Systems
Used by Used in
System Base Symbols humans? computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Hexa-decimal 16 0, 1, … 9, No No
A, B, … F
Student alone in a new paper
Student alone in a paper
Quantities/Counting (1 of 3)
Hexa-
Decimal Binary decimal
0 0 0
1 1 1
2 10 2
3 11 3
4 100 4
5 101 5
6 110 6
7 111 7
Quantities/Counting (2 of 3)
Hexa-
Decimal Binary decimal
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
Quantities/Counting (3 of 3)
Hexa-
Decimal Binary decimal
16 10000 10
17 10001 11
18 10010 12
19 10011 13
20 10100 14
21 10101 15
22 10110 16
Etc.
23 10111 17
Conversion Among Bases

• The possibilities:

Decimal Octal

Binary Hexadecimal
Basic rules
• To convert from b number system to decimal

Decimal

Binary ………. Hexadecimal

Multiply each digit of source by source base raised to rank power


Basic rules
• To convert from decimal to number system b

Decimal

Binary ………. Hexadecimal

Divide whole decimal number by target base downwards


Quick Example

2510 = 110012 = 1916

Base
Decimal to Decimal (just for fun)

Decimal Octal

Binary Hexadecimal

Next slide…
Weight

12510 => 5 x 100 = 5


2 x 101 = 20
1 x 102 = 100
125

Base
Binary to Decimal

Decimal Octal

Binary Hexadecimal
Binary to Decimal

• Technique
– Multiply each bit by 2n, where n is the “weight”
of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results
Example
Bit “0”

1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
Hexadecimal to Decimal

Decimal Octal

Binary Hexadecimal
Hexadecimal to Decimal

• Technique
– Multiply each bit by 16n, where n is the
“weight” of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results
Example

ABC16 => C x 160 = 12 x 1 = 12


B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
Decimal to Binary

Decimal Octal

Binary Hexadecimal
Decimal to Binary

• Technique
– Divide by 2, keep track of the remainder
– First remainder is bit 0 (LSB, least-significant
bit)
– Second remainder is bit 1
– Etc.
Decimal to Binary cont.
• 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
Example
12510 = ?2 2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1

12510 = 11111012
Hexadecimal to Binary

Decimal Octal

Binary Hexadecimal
Hexadecimal to Binary

• Technique
– Convert each hexadecimal digit to a 4-bit
equivalent binary representation
Example
10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112
Decimal to Hexadecimal

Decimal Octal

Binary Hexadecimal
Decimal to Hexadecimal

• Technique
– Divide by 16
– Keep track of the remainder
Example
123410 = ?16

16 1234
16 77 2
16 4 13 = D
0 4

123410 = 4D216
Binary to Hexadecimal

Decimal Octal

Binary Hexadecimal
Binary to Hexadecimal

• Technique
– Group bits in fours, starting on right
– Convert to hexadecimal digits
Example
10101110112 = ?16

10 1011 1011

2 B B

10101110112 = 2BB16
Binary − Hexadecimal
Hex Binary
• 16 = 24 0
1
0000
0001

• Each group of 4 bits represents a 2


3
0010
0011
hexadecimal digit 4
5
0100
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)


Exercise – Convert ...

Hexa-
Decimal Binary decimal
33
1110101
1AF

Skip answer Answer


Exercise – Convert …
Answer

Hexa-
Decimal Binary decimal
33 100001 21
117 1110101 75
431 110101111 1AF
Fractions

• Decimal to decimal (just for fun)


3.14 => 4 x 10-2 = 0.04
1 x 10-1 = 0.1
3 x 100 = 3
3.14
Fractions
• Binary to decimal
10.1011 => 1 x 2-4 = 0.0625
1 x 2-3 = 0.125
0 x 2-2 = 0.0
1 x 2-1 = 0.5
0 x 20 = 0.0
1 x 21 = 2.0
2.6875
Fractions
• Decimal to binary .14579
x 2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001... etc.

p. 50
Exercise – Convert ...
Hexa-
Decimal Binary decimal
29.8
101.1101
C.82

Don’t use a calculator!

Skip answer Answer


Exercise – Convert …

Answer

Hexa-
Decimal Binary decimal
29.8 11101.110011… 1D.CC…
5.8125 101.1101 5.D
12.5078125 1100.10000010 C.82
Binary Addition (1 of 2)
• Two 1-bit values
A B A+B
0 0 0
0 1 1
1 0 1
1 1 10
“two”
Binary Addition (2 of 2)

• Two n-bit values


– Add individual bits
– Propagate carries
– E.g., 1 1
10101 21
+ 11001 + 25
101110 46
Multiplication (1 of 3)

• Decimal (just for fun)


35
x 105
175
000
35
3675
Multiplication (2 of 3)

• Binary, two 1-bit values

A B A×B
0 0 0
0 1 0
1 0 0
1 1 1
Multiplication (3 of 3)

• Binary, two n-bit values


– As with decimal values
– E.g., 1110
x 1011
1110
1110
0000
1110
10011010
Practice unsigned
0110 0110
0101
1. + 5. - 0101

1010 0111
0011
2. + 6. - 0010

1110 1010
0101
3. + 7. - 0111

0111 1110
1010
4. + 8. - 0100
Negative numbers
• How do we write negative binary numbers?
– Prefix numbers with minus symbol?

• 3 approaches:
– Sign and magnitude
– Ones-complement
– Twos-complement

• All 3 approaches represent positive numbers in the


same way
Sign and magnitude
• Most significant bit
(MSB) is the sign bit –7 +0
– 0 ≡ positive –6 1111 0000 +1

– 1 ≡ negative –5 1110 0001 +2


1101 0010
–4 +3
1100 0011
• Remaining bits are the
– 3 1011 0100 + 4
number's magnitude 1010 0101
–2 1001 0110 +5

–1 1000 0111 +6
–0 +7
Complement

• Negative number:
–0 +0
Bitwise complement of –1 1111 0000 +1
positive number –2 1110 0001 +2
1101 0010
– 0111 ≡ 710 –3 +3
1100 0011
– 1000 ≡ –710
– 4 1011 0100 + 4
1010 0101
–5 1001 0110 +5

–6 1000 0111 +6
–7 +7
1’s Complement

• 1’s complement of N is defined as (2n -1)-N.


– If n=4 have (2n -1) being 1 0000 - 1 = 1111
• So for n=4 would subtract any 4-bit binary
number from 1111.
• This is just inverting each bit.
• Example: 1’s complement of 1011001
• is 0100110
2’s complement
• The 2’s complement is defined as 2n-N
• Can be done by subtraction of N from 2n or adding 1 to the
1’s complement of a number.
• For 6 = 0110
– The 1’s complement is 1001
– The 2’s complement is 1010

• Benefits:
– Simplifies arithmetic
– Only one zero!
1.6 Signed Binary Numbers
• To represent negative integers, we need a notation for
negative values.
• It is customary to represent the sign with a bit placed in
the leftmost position of the number since binary digits.
• The convention is to make the sign bit 0 for positive
and 1 for negative.
• Example:
Operation with 2’s complement

• Add 4 and -6
• Will use the 2’s complement of -6 or 1010
4 0100
-6 1010
1110
• And taking the 2’s complement of 1110 get
0001 + 1 = 0010
Complements
• Example 1.7
– Given the two binary numbers X = 1010100 and Y = 1000011,
perform the subtraction (a) X – Y ; and (b) Y − X, by using 2's
complement.

There is no end carry.


Therefore, the answer is
Y – X = − (2's complement
of 1101111) = − 0010001.
Signed Binary Numbers

• The Table lists all


possible four-bit
signed binary
numbers in the
three
representations.
Practice signed
0110 0110
0101
1. + 5. - 0101

1010 0111
0011
2. + 6. - 0010

1110 1010
0101
3. + 7. - 0111

0111 1110
1010
4. + 8. - 0100
Subtraction example

Reference:
COMPUTER ORGANIZATION
AND ARCHITECTURE
DESIGNING FOR PERFORMANCE
NINTH EDITION
William Stallings
Problems from textbook
1.11 Perform the following division in binary: 111011 ÷ 101.

1.12* Add and multiply the following numbers without


converting them to decimal.
(a) Binary numbers 1011 and 101.
(b) Hexadecimal numbers 2E and 34.

1.14 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.
Problems from textbook
1.22 Convert decimal 6,514 to both BCD and ASCII codes. For ASCII, an even parity bit is to be
appended at the left.

1.23 Represent the unsigned decimal numbers 791 and 658 in BCD, and then show the steps
necessary to form their sum.

1.24 Formulate a weighted binary code for the decimal digits, using the following weights:
(a) * 6, 3, 1, 1
(b) 6, 4, 2, 1

1.25 Represent the decimal number 6,248 in


(a) BCD,
(b) excess‐3 code,
(c) 2421 code, and
(d) a 6311 code.
Character codes
Character code is a mapping, often presented in tabular form,
which defines a one-to-one correspondence between characters in a
character repertoire and a set of nonnegative integers. That is, it assigns a
unique numerical code, a code position, to each character in the repertoire.
In addition to being often presented as one or more tables, the code as a
whole can be regarded as a single table and the code positions as indexes.

Examples: character encoding scheme


♣ Binary-Code Decimal (BCD)
♣ Extended Binary Coded Decimal (EBCD)
♣ ASCII
♣ Unicode

Why character codes?


ASCII code
• American Standard Code for Information Interchange (ASCII) Character Code
BCD
♣ BCD is still used primarily in scientific, financial and graphic calculators.
♣ Encoding and Decoding into BCD is easy.
♣ There is an important reason to use BCD instead of pure binary
representations. Binary floating point has no exact representation for numbers
like 0.2. 0.2 in binary would be coded as 0.001100110011…
1.7 Binary Codes
• 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.
Binary Code
• Example:
– Consider decimal 185 and its corresponding
value in BCD and binary:

• BCD addition
Binary Code
• Example:
– Consider the addition of 184 + 576 = 760 in BCD:

• Decimal Arithmetic: Hint 6: using 10’s of BCD


(+375) + (-240) = +135
Binary Codes
• Other
Decimal
Codes
Binary Codes
• Gray Code
– The advantage is that only bit in
the code group changes in going
from one number to the next.
• Error detection.
• Representation of analog data.
• Low power design.
000 001

010 011
100 101

110 111
Binary Storage
• Registers
– A binary cell is a device that possesses two stable states and is capable of storing one of
the two states.
– A register is a group of binary cells. A register with n cells can store any discrete
quantity of information that contains n bits.
n cells 2n possible states
• A binary cell
– Two stable state
– Store one bit of information
– Examples: flip-flop circuits, ferrite cores, capacitor
• A register
– A group of binary cells
– AX in x86 CPU
• Register Transfer
– A transfer of the information stored in one register to another.
– One of the major operations in digital system.
– An example in next slides.
A Digital Computer Example
Memory

Control
CPU unit Datapath

Inputs: Keyboard, Outputs: CRT,


mouse, modem, Input/Output LCD, modem,
microphone speakers
Synchronous or
Asynchronous?
Transfer of information

Figure 1.1 Transfer of information among register


Transfer of information

• The other major


component of a digital
system
– Circuit elements to
manipulate individual
bits of information
– Load-store machine
LD R1;
LD R2;
ADD R3, R2, R1;
SD R3;

Figure 1.2 Example of binary information processing


1.9 Binary Logic
• Definition of Binary Logic
– Binary logic consists of binary variables and a set of logical operations.
– The variables are designated by letters of the alphabet, such as A, B, C, x, y, z,
etc, with each variable having two and only two distinct possible values: 1 and 0,
– Three basic logical operations: AND, OR, and NOT.
Binary Logic
• Truth Tables, Boolean Expressions, and Logic Gates
AND OR NOT
x y z x y z x z
0 0 0 0 0 0 0 1
0 1 0 0 1 1 1 0
1 0 0 1 0 1
1 1 1 1 1 1

z=x•y=xy z=x+y z = x = x’

x x x
y z y z z
Switching Circuits
AND OR
Binary Logic
• Logic gates
– Example of binary signals

3
Logic 1
2
Un-define
1
Logic 0
0

Figure 1.3 Example of binary signals


Binary Logic
• Logic gates
– Graphic Symbols and Input-
Output Signals for Logic gates:

Fig. 1.5 Input-Output signals for gates


Fig. 1.4 Symbols for digital logic circuits
Binary Logic

• Logic gates
– Graphic Symbols and Input-Output Signals for
Logic gates:

Fig. 1.6 Gates with multiple inputs


Assignment #01

Solve all problems and exercises for chapter 1?

Delivering only through email


Boolean Algebra

You might also like